2

I am trying to run a Spring Boot application in a JBoss container. I am having a similar problem to this: Spring boot war doesn´t work on Jboss 7.1, but his solution to just remove actuate from the pom file will not work as I actually do need some actuate functionality.

Stack trace;

14:54:33,794 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/rtsweb]] (MSC service thread 1-5) Exception starting filter applicationContextIdFilter: java.lang.InstantiationException: org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter
    at java.lang.Class.newInstance0(Class.java:359) [rt.jar:1.7.0_21]
    at java.lang.Class.newInstance(Class.java:327) [rt.jar:1.7.0_21]
    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_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]

14:54:33,805 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/rtsweb]] (MSC service thread 1-5) Exception starting filter webRequestLoggingFilter: java.lang.InstantiationException: org.springframework.boot.actuate.trace.WebRequestTraceFilter
    at java.lang.Class.newInstance0(Class.java:359) [rt.jar:1.7.0_21]
    at java.lang.Class.newInstance(Class.java:327) [rt.jar:1.7.0_21]
    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_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]

14:54:33,825 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-5) Error filterStart

I have no idea how to fix or debug this. I have tried changing around some of the versions (Spring-boot as a whole and actuate individually) and have also tried using spring-boot-starter-actuate instead of just spring-boot-actuate but no luck.

Community
  • 1
  • 1
Le Ish Man
  • 451
  • 2
  • 4
  • 20

1 Answers1

1

I resolved this issue by adding a jboss-deployment-structure.xml file to WEB-INF in my webapp folder.

<?xml version="1.0" encoding="UTF-8"?>

<jboss-deployment-structure>
    <deployment>
        <exclude-subsystems>
            <subsystem name="jpa" />
        </exclude-subsystems>
        <exclusions>
            <!-- WFCORE-209 workaround -->
            <module name="javaee.api" />
            <module name="javax.persistence.api" />
            <module name="org.hibernate" />
        </exclusions>
        <dependencies>
            <!-- WFCORE-209 workaround -->
            <module name="javax.activation.api" export="true" />
            <module name="javax.annotation.api" export="true" />
            <module name="javax.ejb.api" export="true" />
            <module name="javax.el.api" export="true" />
            <module name="javax.enterprise.api" export="true" />
            <module name="javax.enterprise.deploy.api" export="true" />
            <module name="javax.inject.api" export="true" />
            <module name="javax.interceptor.api" export="true" />
            <module name="javax.jms.api" export="true" />
            <module name="javax.jws.api" export="true" />
            <module name="javax.mail.api" export="true" />
            <module name="javax.management.j2ee.api" export="true" />
            <!-- <module name="javax.persistence.api" export="true"/> -->
            <module name="javax.resource.api" export="true" />
            <module name="javax.rmi.api" export="true" />
            <module name="javax.security.auth.message.api" export="true" />
            <module name="javax.security.jacc.api" export="true" />
            <module name="javax.servlet.api" export="true" />
            <module name="javax.servlet.jsp.api" export="true" />
            <module name="javax.transaction.api" export="true" />
            <module name="javax.validation.api" export="true" />
            <module name="javax.ws.rs.api" export="true" services="export" />
            <module name="javax.xml.bind.api" export="true" />
            <module name="javax.xml.registry.api" export="true" />
            <module name="javax.xml.soap.api" export="true" />
            <module name="javax.xml.ws.api" export="true" />

            <!-- This one always goes last. -->
            <module name="javax.api" export="true" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>

Full steps taken; Edit the pom file to build as a war instead of a jar;

<groupId>project</groupId>
<artifactId>project-web</artifactId>
<version>0.4.0-SNAPSHOT</version>
<packaging>war</packaging>

Suppress the embedded container;

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

Add an init method for the dispatcher servlet in the WebConfig file;

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        ...
        initDispatcherServlet(servletContext, disps);
        ...
    } 


private void initDispatcherServlet(ServletContext servletContext, EnumSet<DispatcherType> disps) {

        // Using listener to be able to get the Dispatcher Servlet not yet initialized
        servletContext.addListener(new ServletContextListener() {

            @Override
            public void contextInitialized(ServletContextEvent event) {
                try {
                    Map<String, ? extends ServletRegistration> servlets=null;
                    servlets = event.getServletContext().getServletRegistrations();
                    Set<String> keys = servlets.keySet();       

                    log.debug("Registred servlets : "+keys);

                    ServletRegistration dspSrvlt = servlets.get("dispatcherServlet");
                    if(dspSrvlt != null) {
                        Collection<String> maps = dspSrvlt.getMappings();
                        log.debug("Dispatcher servlet mapping size : "+maps.toArray().length);
                        log.debug("Servlet dispatcher mapping : "+maps);
                        if( !maps.contains("/*") ) {
                            log.debug("Adding /* for Spring Dispatcher servlet");
                            servlets.get("dispatcherServlet").addMapping("/*");
                        }
                    } else {
                        log.warn("Unable to change the Servlet Request dispatcher mapping to allow deployment with JBoss");
                    }
                } catch (Exception e) {
                    log.warn("Unable to change the Servlet Context to allow deployment with JBoss");
                }

            }

            @Override
            public void contextDestroyed(ServletContextEvent arg0) {
            }
        });

    }

These are all the steps I took when deploying a JHipster generated app to JBoss 7.1/EAP 6.3.

Hope it helps as it was a real pain.

Le Ish Man
  • 451
  • 2
  • 4
  • 20
  • 1
    Can you paste the content of this file? I use it for disabling JPA that comes from JBoss but existence of this file itself does not solve problems with filter and servlet instantiation. – Maciej Walkowiak May 19 '15 at 09:35
  • Have added the xml file as well as all of the other steps I took to resolve the issue. – Le Ish Man May 19 '15 at 10:16