Jboss部署SpringBoot项目中遇到的问题
说明:Jboss7及之前名称都是Jboss,在8及之后的版本,名称改为wildfly,请知悉
下篇链接:Jboss部署SpringBoot项目中遇到的问题-2
lombok报错
WARN [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015852: Could not index class module-info.class at /D:/wildfly-8.1.0.Final/bin/content/spring-shiro-demo-0.0.1-SNAPSHOT.war/WEB-INF/lib/lombok-1.16.22.jar: java.lang.IllegalStateException: Unknown tag! pos=4 poolCount = 42
at org.jboss.jandex.Indexer.processConstantPool(Indexer.java:619) [jandex-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.jandex.Indexer.index(Indexer.java:653) [jandex-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.as.server.deployment.annotation.ResourceRootIndexer.indexResourceRoot(ResourceRootIndexer.java:100) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.server.deployment.annotation.AnnotationIndexProcessor.deploy(AnnotationIndexProcessor.java:51) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_131]
- 原因:lombok版本过高,Jboss在解析时报错
- 解决方案:降低lombok版本即可,可以从上面的1.16.22改为1.16.0
logback等日志报错
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS017327: Deployment error processing SCI for jar: logback-classic-1.1.11.jar
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.loadSci(ServletContainerInitializerDeploymentProcessor.java:207)
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:128)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.1.0.Final.jar:8.1.0.Final]
... 5 more
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS017327: Deployment error processing SCI for jar: logback-classic-1.1.11.jar
at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.loadSci(ServletContainerInitializerDeploymentProcessor.java:199)
... 7 more
- 原因:logback与Jboss中自带的jar产生了冲突
- 解决方案:Sringboot项目中的pom.xml排除logback,如果项目中有spring-boot-start-logging的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
- 解决方案2:如有项目中有spring-boot-starter-web的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
Slf4jLoggerFactory无法转换为LoggerContext
- 问题:报java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext异常
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[default]] (http--0.0.0.0-9000-1) Servlet.service() for servlet default threw exception: java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
at com.ronhe.romp.commons.log.util.LogUtil.getLogger(LogUtil.java:155) [romp-common-8.0.0.jar:8.0.0]
at com.ronhe.romp.commons.log.util.LogUtil.log(LogUtil.java:75) [romp-common-8.0.0.jar:8.0.0]
at com.ronhe.romp.commons.log.util.LogUtil.debug(LogUtil.java:151) [romp-common-8.0.0.jar:8.0.0]
at com.ronhe.romp.auth.shiro.LoginErrorInfo.writeError(LoginErrorInfo.java:87) [romp-auth-8.0.0.jar:8.0.0]
at com.ronhe.romp.auth.shiro.filter.SystemAccessControlFilter.isAccessAllowed(SystemAccessControlFilter.java:135) [romp-auth-8.0.0.jar:8.0.0]
at org.apache.shiro.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:162) [shiro-web-1.2.3.jar:1.2.3]
at org.apache.shiro.web.filter.PathMatchingFilter.isFilterChainContinued(PathMatchingFilter.java:203) [shiro-web-1.2.3.jar:1.2.3]
at org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:178) [shiro-web-1.2.3.jar:1.2.3]
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131) [shiro-web-1.2.3.jar:1.2.3]
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-web-1.2.3.jar:1.2.3]
- 原因:slf4j的jar与Jboss自带的jar产生了冲突
- 解决:项目中使用 jboss-deployment-structure.xml 文件进行对冲突依赖排除
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
<!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
<exclusions>
<module name="org.slf4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
- 解决2:如果上述排除后还不可以,增加排除org.slf4j.impl
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<exclusions>
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
</exclusions>
</deployment>
</jboss-deployment-structure>
wildfly服务,调用接口返回时报jackson相关错误
- 问题:wildfly服务可以正常启动,方法调用可以正常进入方法,但是返回时报错,报NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType
10:29:33,542 ERROR [org.springframework.boot.web.support.ErrorPageFilter] (default task-1) Forwarding to error page from request [xxx.do] due to exception [com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;]:
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:278) [spring-web-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:106) [spring-web-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:231) [spring-webmvc-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:174) [spring-webmvc-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81) [spring-web-4.3.22.RELEASE.jar:4.3.22.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:113) [spring-webmvc-4.3.22.RELEASE.jar:4.3.22.RELEASE]
- 原因:由于jboss的module中自带Jackson而且版本较低,无法和Springboot2.x之后的兼容,Jackson相关jar包与wildfly自带的jar产生了冲突
- 解决方案:项目中使用 jboss-deployment-structure.xml 文件进行对冲突依赖排除
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<exclusions>
<!-- 所有相关Jackson的包都要去除,不然可能会有其他错误 -->
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
<module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" />
<module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" />
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
</exclusions>
</deployment>
</jboss-deployment-structure>
wildfly服务,调用接口返回时报错NullPointerException
- 问题:wildfly服务可以正常启动,方法调用可以正常进入方法,但是返回时报错,报NullPointExeception
19:31:59,167 ERROR [org.springframework.boot.web.support.ErrorPageFilter] (default task-4) Forwarding to error page from request [/xxx.do] due to exception [null]: java.lang.NullPointerException
at java.util.ArrayList.<init>(ArrayList.java:177) [rt.jar:1.8.0_131]
at io.undertow.servlet.spec.HttpServletResponseImpl.getHeaders(HttpServletResponseImpl.java:248) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at javax.servlet.http.HttpServletResponseWrapper.getHeaders(HttpServletResponseWrapper.java:303) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServletResponseWrapper.getHeaders(HttpServletResponseWrapper.java:303) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at org.springframework.http.server.ServletServerHttpResponse$ServletResponseHttpHeaders.get(ServletServerHttpResponse.java:161) [spring-web-4.3.22.RELEASE.jar:4.3.22.RELEASE]
- 原因:第二句报错 at io.undertow…[undertow-servlet-1.0.15.Final.jar:1.0.15.Final],undertow-servlet版本过低导致,也可以说是wildfly的一个bug
- 解决方案:升级wildfly自带的undertow-servlet.jar的版本
- 本地wildfly包中:D:\wildfly-8.1.0.Final\modules\system\layers\base\io\undertow\servlet\main\module.xml
undertow-servlet-1.0.15.Final.jar中有bug导致问题出现。 - 升级undertow-servlet版本为undertow-servlet-1.1.8.Final.jar,jar版本下载地址为
- MVN中央仓库地址:https://mvnrepository.com/artifact/io.undertow/undertow-servlet/1.1.8.Final
- 并修改module.xml配置为如下
<module xmlns="urn:jboss:module:1.3" name="io.undertow.servlet">
<resources>
<resource-root path="undertow-servlet-1.1.8.Final.jar"/>
</resources>
...
</module>
Shiro报错:ShiroFilterFactoryBean$SpringShiroFilter 无法实例化
- 问题:java.lang.InstantiationException: org.apache.shiro.spring.web.ShiroFilterFactoryBean$SpringShiroFilter
20:21:56,873 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/]] (MSC service thread 1-6) Exception starting filter shiroFilter: java.lang.InstantiationException: org.apache.shiro.spring.web.ShiroFilterFactoryBean$SpringShiroFilter
at java.lang.Class.newInstance(Class.java:364) [rt.jar:1.7.0_79]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:80) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:441) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
- 原因:没有为项目配置web.xml引导shiroFilter
- 解决方案:我们普通的SSM项目都配置的有web.xml来引导shiroFilter,SpringBoot项目没有web.xml文件来进行引导,只需要添加web.xml文件即可
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<!--shiro安全认证过滤器,filter-name的值会在spring(或springMVC)的配置文件中使用-->
<filter>
<filter-name>shiroFilter</filter-name>
<!--使用的是springWeb的拦截器代理,具体实现在springmvc-shiro中配置-->
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>
.do请求不生效
- 解决方案:在web.xml增加.do请求的拦截处理
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
...
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>spring mvc 配置文件</description>
<param-name>contextConfigLocation</param-name>
<param-value><!-- classpath:applicationContext.xml --></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
上下文路径(contextPath)为项目名,需要自定义为其他
- 问题:服务启动后,contextPath为项目名,而需要自定义
20:33:58,323 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/xxx]] (MSC service thread 1-2) Initializing Spring embedded WebApplicationContext
// xxx为项目名
- 解决方案:增加jboss-web.xml,内容如下,可自行配置
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/</context-root>
</jboss-web>
web服务启动端口的设置
- 更改D:\wildfly-8.1.0.Final\standalone\configuration文件夹下的standalone.xml文件
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
<socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
<!-- 如果需要更改应用的http的访问端口,修改下面的一项即可 -->
<socket-binding name="http" port="${jboss.http.port:9000}"/>
<socket-binding name="https" port="${jboss.https.port:8443}"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="localhost" port="25"/>
</outbound-socket-binding>
</socket-binding-group>