I`m trying to run a simple application with spring java based configuration on jboss, but no success. This application works fine both on jetty and tomcat. The jboss log loo
We have a spring-boot (1.1.4) project on JBoss EAP 6.2 (my customer's requirement...)
I found a solution to run it on JBoss EAP 6.2.0 GA and keep capability to run on Apache Tomcat 7 container.
Initially my project run in embedded mode, so I need to create and change some files to run on containers.
To run on Tomcat as root application I created context.xml: /src/main/webapp/META-INF/context.xml
To run on JBOSS EAP 6.2.0 GA as root application I created jboss-web.xml: /src/main/webapp/WEB-INF/jboss-web.xml
/
I created a class, because JBoss servlet mapping works as /* but not with / :
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
/**
* Working without web.xml with container (not em,bedded mode).
* JBOSS EAP 6.2 specific: you need to map dispatcherServlet to /* .
*/
public class ContainerWebXml extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TomcatStart.class);
}
/**
* JBOSS EAP 6.2 mapping.
*
* @param container
* @throws ServletException
*/
@Override
public void onStartup(ServletContext container) throws ServletException {
WebApplicationContext context = getContext();
Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context));
registration.setLoadOnStartup(1);
registration.addMapping("/*"); // required JBOSS EAP 6.2.0 GA
super.onStartup(container);
}
private WebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(TomcatStart.class.getName());
return context;
}
}
Do not forget call super.onStartup(container);
Changes in pom.xml:
org.springframework.boot
spring-boot-starter-tomcat
provided
If you use spring.profile, than you need to set as env. variable.
I run JBoss EAP 6.2.0 GA as standalone mode:
export JAVA_OPTS="-Dspring.profiles.active=local"
.../jboss-eap-6.2/bin/standalone.sh
If you run on Tomcat, then do not forget to set -Dspring.profiles.active=local
As I see the server.port setting will be ignored when you run on container.