1
votes

I followed the instructions on https://spring.io/blog/2014/03/07/deploying-spring-boot-applications to deploy a Spring Boot application to a WebSphere Liberty profile.

But, it's not working. When I hit the URL in a browser, I'm getting Context Root Not Found error message.

enter image description here

In the log file, I could actually see the Spring Boot is being started, but it seems to fail to get to the entry point.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.1.RELEASE)
18:01:11.507 [Default Executor-thread-131] INFO  us.com.xxx.Application - Starting Application on mylaptop with PID 75199 (/opt/IBM/WebSphere/Liberty/usr/servers/defaultServer/apps/expanded/mywar.war/WEB-INF/classes started by root in /opt/IBM/WebSphere/Liberty/usr/servers/defaultServer)
18:01:11.512 [Default Executor-thread-131] DEBUG us.com.xxx.Application - Running with Spring Boot v1.4.1.RELEASE, Spring v4.3.3.RELEASE
18:01:11.513 [Default Executor-thread-131] INFO  us.com.xxx.Application - No active profile set, falling back to default profiles: default

Here's my Application class:

@EnableSwagger2
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

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

My build.gradle to build the war:

apply plugin: "war"
war {
    baseName = "mywar"
    version = "0.1"
}

apply plugin: "spring-boot"

providedRuntime "org.springframework.boot:spring-boot-starter-tomcat"

Is there anything I missed in my Sprint Boot application? Is there any feature I need to enable in the Liberty server.xml?

1
have you figured out what was wrong ? - JustTry
No unfortunately. I decided to never touch any WebSphere products again. - His
Wise decision :) - JustTry

1 Answers

0
votes

I was able to get the tutorial working locally with the following features enabled in my server.xml:

<featureManager>
  <feature>beanValidation-1.1</feature>
  <feature>cdi-1.2</feature>
  <feature>jaxrs-2.0</feature>
  <feature>servlet-3.1</feature>
</featureManager>

It can be kind of tricky to know what features you need to have enabled, so to be safe you can just enable the javaee-7.0 feature, which will pull in the full Java EE 7 stack. However, your server restarts will be slower in your dev environment, since you are starting all these extra features.

In this case, these 4 features are needed because:

  • CDI: needed for anything spring related as far as I know, since spring does lots of dependency injectin
  • JAXRS: because the sample uses a rest endpoint
  • Servlet: because our application extends SpringBootServletInitializer
  • Bean Validation: because the hello method uses the @PathVariable annotation on a method parameter

My Application.java looked like this:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

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

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

    private static Class<Application> applicationClass = Application.class;
}


@RestController
class GreetingController {

    @RequestMapping("/hello/{name}")
    String hello(@PathVariable String name) {
        return "Hello, " + name + "!";
    }
} 

Once my server was started, I went to the url http://localhost:9080/demo/hello/aguibert and got the welcome message.