suman j
suman j

Reputation: 6960

Deploying standalone war file from Spring Boot to Jetty

Am trying to deploy a war file built with Spring Boot to standalone Jetty webapps folder and start Jetty. During Spring context initialization, I see exceptions:

Caused by: 
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)

Below is my gradle dependency list:

dependencies {
    compile(
        "org.springframework.boot:spring-boot-starter-actuator:1.1.4.RELEASE",
        "org.springframework.security:spring-security-web:3.2.3.RELEASE",
        "org.springframework.security:spring-security-config:3.2.3.RELEASE",
        'javax.validation:validation-api:1.0.0.GA',
        'org.hibernate:hibernate-validator:4.0.0.GA',
        "org.codehaus.groovy:groovy-all:2.1.1",
        'com.google.code.gson:gson:2.2.1',
        "javax.servlet:javax.servlet-api:3.1.0",
        "com.sun.jersey:jersey-server:1.16",
        "com.sun.jersey:jersey-client:1.16",
        "com.sun.jersey:jersey-core:1.16",
        "com.fasterxml.jackson.jaxrs:jackson-jaxrs-providers:2.3.2",
        "com.sun.jersey:jersey-servlet:1.16",
        "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2",
        "com.sun.jersey.contribs:jersey-spring:1.16",
        "org.springframework:spring-beans:4.0.6.RELEASE",
        'com.wordnik:swagger-jersey-jaxrs_2.10:1.3.5',
        'com.fasterxml.jackson.core:jackson-core:2.3.0',
        "org.springframework:spring-web:4.0.6.RELEASE",
        "org.springframework:spring-core:4.0.6.RELEASE",
        "org.springframework:spring-tx:4.0.6.RELEASE",
        "org.springframework:spring-expression:4.0.6.RELEASE",
        "org.springframework:spring-webmvc:4.0.6.RELEASE",
        "org.springframework:spring-context:4.0.6.RELEASE",
        "org.jasypt:jasypt-spring3:1.9.1",
        "com.sun.jersey.contribs:jersey-multipart:1.16",
        "org.aspectj:aspectjweaver:1.7.4",
        "org.springframework:spring-aspects:4.0.6.RELEASE",
        "org.springframework:spring-aop:4.0.6.RELEASE",
        'javax.validation:validation-api:1.0.0.GA',
        'org.hibernate:hibernate-validator:4.0.0.GA'
    )
    compile ("org.springframework.boot:spring-boot-starter-web:1.1.4.RELEASE") {
        exclude module:'spring-boot-starter-tomcat'
    }

I am using ApplicationInitializer class as suggested in Spring Boot docs. What am I missing? How to get past this exception? I have Jetty 9.x server.

class ApplicationInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        Properties props = getPropertiesFromArgs()
        return new SpringApplicationBuilder([Application, "classpath:/META-INF/com/foo/testapp/bootstrap.xml"] as Object[])
            .properties(props)
    }

Upvotes: 0

Views: 1431

Answers (1)

suman j
suman j

Reputation: 6960

Found the issue. initializer class was creating a new application builder instead of using the input parameter. Changing it to below worked fine.

class ApplicationInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        Properties props = getPropertiesFromArgs()     
        return application.sources([Application, "classpath:/META-INF/com/foo/testapp/bootstrap.xml"] as Object[])
            .properties(props)

    }

Upvotes: 1

Related Questions