我有一个使用Gradle依赖项在Spring Boot中编写的简单示例应用程序。它在呼叫localhost时说helloworld:8080 /问候。我将其打包为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
答案 0 :(得分:17)
要在独立的servlet容器中运行Spring Boot应用程序,您需要告诉容器如何启动应用程序。您可以通过扩展SpringBootServletInitializer
并重写configure
方法来为您的应用程序提供配置类。这在getting started guide on converting a jar to a 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);
}
}