Spring boot war doesn´t work on Jboss 7.1

2020-03-30 07:06发布

I´m trying to deploy a Spring boot application on Jboss. I follow this tutorial for convert my jar in to a war file. But when i try to run the application on Jboss it´s give me this error:

17:02:31,462 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter applicationContextIdFilter: java.lang.InstantiationException: org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextFilterConfiguration$1
    at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
    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)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,472 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter webRequestLoggingFilter: java.lang.InstantiationException: org.springframework.boot.actuate.trace.WebRequestTraceFilter
    at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
    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)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,480 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter authenticationFilter: java.lang.InstantiationException: br.gov.rs.defensoria.ldap.service.authentication.AuthenticationFilter
    at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
    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)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,484 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter errorPageFilter: java.lang.IllegalAccessException: Class org.jboss.as.web.deployment.WebInjectionContainer can not access a member of class org.springframework.boot.context.web.ErrorPageFilter with modifiers ""
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109) [rt.jar:1.7.0_51]
    at java.lang.Class.newInstance(Class.java:368) [rt.jar:1.7.0_51]
    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)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,493 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Exception starting filter metricFilter: java.lang.InstantiationException: org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration$MetricsFilter
    at java.lang.Class.newInstance(Class.java:359) [rt.jar:1.7.0_51]
    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)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,505 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Error filterStart
17:02:31,505 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Context [/ldap-service-1.0-SNAPSHOT] startup failed due to previous errors
17:02:31,510 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ldap-service-1.0-SNAPSHOT]] (MSC service thread 1-2) Closing Spring root WebApplicationContext
17:02:31,511 INFO  [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (MSC service thread 1-2) Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2222014c: startup date [Thu Apr 24 17:02:23 BRT 2014]; root of context hierarchy
17:02:31,514 INFO  [org.springframework.context.support.DefaultLifecycleProcessor] (MSC service thread 1-2) Stopping beans in phase 0
17:02:31,523 INFO  [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter] (MSC service thread 1-2) Unregistering JMX-exposed beans on shutdown
17:02:31,529 INFO  [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] (MSC service thread 1-2) Closing JPA EntityManagerFactory for persistence unit 'default'
17:02:31,554 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": JBAS018040: Failed to start context
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
17:02:31,774 INFO  [org.jboss.as.server] (HttpManagementService-threads - 1) JBAS015870: Deploy of deployment "ldap-service-1.0-SNAPSHOT.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host.\"/ldap-service-1.0-SNAPSHOT\"" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host.\"/ldap-service-1.0-SNAPSHOT\": JBAS018040: Failed to start context"}}
17:02:31,850 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment ldap-service-1.0-SNAPSHOT.war in 83ms
17:02:31,852 INFO  [org.jboss.as.controller] (HttpManagementService-threads - 1) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": org.jboss.msc.service.StartException in service jboss.web.deployment.default-host."/ldap-service-1.0-SNAPSHOT": JBAS018040: Failed to start context

My app Spring config file

package myapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {
    private static Class<Application> applicationClass = Application.class;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }
}

And here is my pom.xml

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>war</packaging>
<name>myapp</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.2.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <!-- tag::jetty[] -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.5.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.0.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- end::jetty[] -->
    <!-- tag::actuator[] -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!-- end::actuator[] -->
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core-tiger</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>16.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.8.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>4.0.2.RELEASE</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>

<properties>
    <start-class>myapp.Application</start-class>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>
</properties>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
        </plugin>
        <plugin>
            <groupId>com.googlecode.flyway</groupId>
            <artifactId>flyway-maven-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
                <url>jdbc:sqlserver://dpepoaap02\SQLEXPRESS;Databasename=dev_db_ldap_service</url>
                <user>user_dev</user>
                <password>dpe123</password>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>localRepo</id>
        <url>file://M://</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

Some idea? Thanks!

2条回答
仙女界的扛把子
2楼-- · 2020-03-30 07:18

spring-boot on compile generate two files(.war).

myapp-0.0.1-SNAPSHOT
myapp-0.0.1-SNAPSHOT.war.original

If you wan to deploy to JBoss 7.1 you need to rename myapp-0.0.1-SNAPSHOT.war.original to e.g myapp-0.0.1.war(remove .original extension) and deploy to server.

查看更多
疯言疯语
3楼-- · 2020-03-30 07:25

The main issue with deploying spring-boot is explained here

The post is a bit old by now and does not apply to the current spring-boot (1.3.3 as of this writing).

What is happening in your case is that some filter in spring-boot actuator do not have default constructors which JBoss will try to call so to get around this you need to do the following (This is for current spring-boot 1.3.3):

Create an ApplicationContext which will wrap all bean filters in a delegating class which has a default constructor. We can use spring's DelegatingFilterProxy for that

public class JBossWebApplicationContext extends AnnotationConfigEmbeddedWebApplicationContext {

private final Logger log = LoggerFactory.getLogger(getClass());

@Override
protected Collection<ServletContextInitializer> getServletContextInitializerBeans() {
    Collection<ServletContextInitializer> servletContextInitializerBeans = super.getServletContextInitializerBeans();
    for (ServletContextInitializer servletContextInitializerBean : servletContextInitializerBeans) {
        if (servletContextInitializerBean instanceof FilterRegistrationBean) {
            FilterRegistrationBean frb = (FilterRegistrationBean) servletContextInitializerBean;
            try {
                Field field = FilterRegistrationBean.class.getDeclaredField("filter");
                field.setAccessible(true);
                Filter origFilter = (Filter) field.get(frb);
                frb.setFilter(new DelegatingFilterProxy(origFilter));
            } catch (NoSuchFieldException | IllegalAccessException e) {
                throw new BeanCreationException("Error setting up bean. It does not have a filter field", e);
            }

        }
    }

    return servletContextInitializerBeans;
}
}

Then in your springboot main class make sure to use the context we created above:

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    application.sources(MyApplication.class);
    application.contextClass(JBossWebApplicationContext.class);
    return super.configure(application);
}

public static void main(String[] args) throws Exception {
    SpringApplication app = new SpringApplication(MyApplication.class);
    app.setApplicationContextClass(JBossWebApplicationContext.class);
    app.run(args);
}
}

Lastly you need to make sure your servlet path is configured to be "/*" since JBoss 7.1 does not seem to work with only the default (/). This can be configured in your application.yml (or application.properties)

server:
  servletPath: /*

This should allow you to deploy a springBoot application in JBoss 7.1 (Tested myself on 7.1.3)

Some extra points:

  • I have NOT tested this extensively and therefore you should make sure things are behaving as they should be before relying on this solution
  • I really don't like having to call reflection to get the FRB underlying filter but unfortunately the getFilter method is protected
  • This solution can probably be improved upon by someone who is more versed into spring than I am
查看更多
登录 后发表回答