【发布时间】:2016-03-29 09:56:18
【问题描述】:
我有一个利用 PrimeFaces、弹性搜索、Spring boot 的应用程序。
下面是pom.xml,
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.acn.hps.aops.demo</groupId>
<artifactId>PSCommandCenter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>CommandCentre</name>
<description>Command Center Application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.geocoder-java</groupId>
<artifactId>geocoder-java</artifactId>
<version>0.16</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<!-- Primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.3.4</version>
</dependency>
<!-- JSF dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Elastic Search dependencies -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>primefaces</id>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
下面是它的弹簧配置,
@SpringBootApplication
public class CommandCentreApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) {
SpringApplication.run(CommandCentreApplication.class, args);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/home.jsf");
}
@Bean
ServletRegistrationBean facesServletRegistration() {
return new ServletRegistrationBean() {
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
FacesInitializer facesInitializer = new FacesInitializer();
facesInitializer.onStartup(Collections.singleton(CommandCentreApplication.class),
servletContext);
servletContext.setInitParameter("primefaces.THEME", "redmond");
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "0");
servletContext.setInitParameter("facelets.SKIP_COMMENTS", "true");
}
};
}
@Bean
ServletRegistrationBean pushServletRegistration(){
ServletRegistrationBean pushServlet = new ServletRegistrationBean(new PushServlet(), "/primepush/*");
pushServlet.addInitParameter("org.atmosphere.annotation.packages", "org.primefaces.push");
pushServlet.addInitParameter("org.atmosphere.cpr.packages", "com.acn.hps.aops.demo.map.service.channel");
pushServlet.setAsyncSupported(true);
pushServlet.setLoadOnStartup(0);
pushServlet.setOrder(Ordered.HIGHEST_PRECEDENCE);
return pushServlet;
}
}
还有我的弹性搜索的配置,
@Bean
public Client client(){
TransportClient client= new TransportClient();
TransportAddress address = new InetSocketTransportAddress(PropertiesLoader.esIP, PropertiesLoader.esPort);
client.addTransportAddress(address);
return client;
}
当我从我的 IDE (Eclipse) 执行该应用程序时,它会按预期运行,但是当我从它的 jar 执行应用程序时,我会收到以下异常,
java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config 在 java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_45].
我搜索了这个异常,发现添加了jstl的jar来避免这个错误。但是我在tomcat的罐子里已经有了jstl的罐子。而且,如果这是问题所在,那么我应该在从我的 IDE 执行时遇到相同的异常。
您可以参考我用作应用程序大纲的this github 代码。我也面临同样的问题。
【问题讨论】:
-
@balusC 它不是重复的,因为我已经提到此代码在 IDE 中正常工作,当我通过 Spring Boot 创建 jar 并执行 jar 时,我遇到了这个问题。而且我还尝试添加提到的 JSTL,但它仍然无法正常工作。
-
查看建议后,我在 pom 中添加了提到的 jar 依赖项,我收到此警告“为 jstl pom.xml /PSCommandCenter 第 91 行 Maven pom 加载问题复制托管版本 1.2”并且找不到此资源控制台中出现异常以及此消息,“JSF1091:找不到文件 /home.jsp 的 MIME 类型。要解决此问题,请将 mime 类型映射添加到应用程序 web.xml。而且我的问题是如果我的应用程序在 IDE 中使用相同的资源,那么为什么它的 jar 不是?
-
你可以看看github的链接。它具有我正在使用的相同项目大纲和它的小项目大纲,以便您可以复制此问题。感谢您的回复。
标签: maven spring-boot jstl classnotfoundexception embedded-tomcat-8