3
votes

Building on the example here: https://github.com/Pentadrago/spring-boot-example-wicket
And taking into account the jar-to-war guide here: https://spring.io/guides/gs/convert-jar-to-war/
I'd like to convert my existing Wicket + Spring (using data-jpa and security) to Spring Boot. It's been fairly easy to get the fat-jar setup to work, but it has so far proved impossible for me to convert this setup into a .war file to deploy in Tomcat.

The issue stems from the conflicting instructions to:

  • on the one hand extends org.springframework.boot.context.web.SpringBootServletInitializer from a non-@Configuration class for the jar-to-war conversion guide,
  • while on the other implements org.springframework.boot.context.embedded.ServletContextInitializer for a @Configuration marked class for the fat-jar Wicket example.

I've not been able to align the two such that I get a working application both when debugging with the embedded container, and when deployed as .war in Tomcat.

Can anyone tell me how I can setup a spring-boot enabled wicket application that I can deploy as a .war file?

1

1 Answers

2
votes

What I did and got the application to work was the following:

I checked out the example project https://github.com/Pentadrago/spring-boot-example-wicket that you posted.

Then following the code on the https://spring.io/guides/gs/convert-jar-to-war/ guide all I did was to make the following changes:

Change build.gradle to:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'

jar {
    version =  '0.0.1'
}

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile(
        "org.springframework.boot:spring-boot-starter",
        "org.springframework.boot:spring-boot-starter-logging",

        "org.springframework:spring-web:4.0.3.RELEASE",
        "org.apache.wicket:wicket-spring:6.15.0",
        )

    testCompile(
        "org.springframework.boot:spring-boot-starter-test",
    )

    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}

Add the following class:

HelloWebXml.java

package spring.boot.example.wicket;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

public class HelloWebXml extends SpringBootServletInitializer {

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

Those where the only changes I made and deployed to Tomcat 7 without any problems.

Here is the excerpt from the log that shows that wicked got started

2014-08-27 20:57:41.396 INFO 2708 --- [on(3)-127.0.0.1] org.apache.wicket.Application : [wicket-filter] init: Wicket core library initializer

I am not sure what your source of confusion is but you have to understand that SpringBootServletInitializer and ServletContextInitializer serve different purposes.