Spring Boot(使用Gradle)+ WebSphere Liberty =找不到上下文根

时间:2016-10-27 07:11:10

标签: java gradle spring-boot websphere-liberty

我按照https://spring.io/blog/2014/03/07/deploying-spring-boot-applications上的说明将Spring Boot应用程序部署到WebSphere Liberty配置文件。

但是,它不起作用。当我在浏览器中点击URL时,我收到Context Root Not Found错误消息。

enter image description here

在日志文件中,我实际上可以看到Spring Boot正在启动,但似乎无法进入入口点。

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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

这是我的Application类:

@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);
    }
}

构建战争的build.gradle:

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

apply plugin: "spring-boot"

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

我的Sprint Boot应用程序中是否有任何遗漏?我是否需要在Liberty server.xml中启用任何功能?

1 个答案:

答案 0 :(得分:0)

我能够在本地工作,并在server.xml中启用了以下功能:

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

了解您需要启用哪些功能可能有点棘手,因此为了安全起见,您可以启用javaee-7.0功能,该功能将引入完整的Java EE 7堆栈。但是,您的开发环境中的服务器重启速度会变慢,因为您正在启动所有这些额外功能。

在这种情况下,需要这4个功能,因为:

  • CDI:就我所知,任何与春天有关的东西都需要,因为春天有很多依赖注入
  • JAXRS:因为示例使用了休止端点
  • Servlet:因为我们的应用程序扩展了SpringBootServletInitializer
  • Bean验证:因为hello方法在方法参数
  • 上使用@PathVariable注释

我的Application.java看起来像这样:

@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 + "!";
    }
} 

我的服务器启动后,我转到了网址http://localhost:9080/demo/hello/aguibert并收到了欢迎信息。