【问题标题】:Spring Boot (with Gradle) + WebSphere Liberty = Context Root Not FoundSpring Boot(使用 Gradle)+ WebSphere Liberty = 找不到上下文根
【发布时间】:2016-10-27 07:11:10
【问题描述】:

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

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

在日志文件中,我实际上可以看到 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

这是我的应用程序类:

@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 中启用任何功能吗?

【问题讨论】:

  • 你找出问题所在了吗?
  • 很遗憾没有。我决定再也不碰任何 WebSphere 产品了。
  • 明智的决定:)

标签: java gradle spring-boot websphere-liberty


【解决方案1】:

通过在我的 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:据我所知,任何与 spring 相关的东西都需要,因为 spring 做了很多依赖注入
  • JAXRS:因为示例使用了一个休息端点
  • Servlet:因为我们的应用扩展了SpringBootServletInitializer
  • Bean Validation:因为 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 + "!";
    }
} 

我的服务器启动后,我访问了 url http://localhost:9080/demo/hello/aguibert 并收到了欢迎消息。

【讨论】:

  • 遗憾的是它对我不起作用:(以及您如何提供应用程序位置名称作为演示是它的一些东西
猜你喜欢
  • 2015-05-22
  • 1970-01-01
  • 2018-06-21
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-13
相关资源
最近更新 更多