5

我有一个使用 Gradle 依赖项用 Spring Boot 编写的简单示例应用程序。它在调用 localhost:8080/greetings 时显示 helloworld。我将它打包为 WAR 并将其作为 myWebApp.war 部署到 Tomcat。

当我调用 localhost:8080/myWebApp/greetings 时,我得到 404。我应该从下面的 catalina.log 中推断出什么

  Sep 17, 2014 1:43:09 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Sep 17, 2014 1:43:09 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive D:\C813507\Tomcat7\apache-tomcat-7.0.54\webapps\cftsample.war
Sep 17, 2014 1:43:09 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\C813507\Tomcat7\apache-tomcat-7.0.54\webapps\cftsample\WEB-INF\lib\tomcat-embed-core-7.0.54.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Sep 17, 2014 1:43:09 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\C813507\Tomcat7\apache-tomcat-7.0.54\webapps\cftsample\WEB-INF\lib\tomcat-embed-el-7.0.54.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
Sep 17, 2014 1:43:13 AM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [138] milliseconds.
Sep 17, 2014 1:43:13 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive D:\C813507\Tomcat7\apache-tomcat-7.0.54\webapps\cftsample.war has finished in 4,385 ms
4

1 回答 1

18

要在独立的 servlet 容器中运行 Spring Boot 应用程序,您需要告诉容器如何启动应用程序。您可以通过扩展SpringBootServletInitializer和覆盖该configure方法来为您的应用程序提供配置类来做到这一点。这在将 jar 转换为 war 的入门指南中进行了描述。

你通常会得到这样的类:

@Configuration
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

    // Used when launching as an executable jar or war
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

    // Used when deploying to a standalone servlet container
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}
于 2014-09-17T08:45:47.143 回答