所以我是Spring的新手-所以我想我会尝试Spring Boot
我正在使用Maven进行构建-我设置了一个视图请求,当我以“ App”的身份运行它时,它似乎会自动启动并在默认的8080端口提供服务,因此当我调用localhost:8080/service它时,一切都很好。
localhost:8080/service
但是,当我尝试将其打包为WAR部署到服务器时,它不起作用
所以我想我会回到基础知识,并将其部署到本地的tomcat服务器上,看看会发生什么
所以首先什么也没发生-404-在Google搜索时发现我需要包含这样的Web入口点-这是我的主要课程
@ComponentScan @EnableAutoConfiguration public class App extends SpringBootServletInitializer { public static void main( String[] args ) { SpringApplication.run(App.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(appClass); } private static Class<App> appClass = App.class; }
因此它看起来像是可以正常工作的,在控制台中,我可以看到红色的catalina启动文本,然后我看到了Spring Boot的启动过程(之前从未见过)
但是,当我尝试致电该服务时,localhost:8080/service我仍然收到404
当我将其作为“ App”运行时
有什么明显的要做的事情吗?创造战争
我已经解压缩了WAR,它看起来还不错-有一个WEB-INF和一组依赖项,等等。
任何帮助都是好的-因为在将Spring Boot应用程序部署为WAR时有人遇到类似的问题?
现在,我可以展开将其正确部署在本地Tomcat 7服务器上的战斗-但是当我尝试部署到外部托管的Tomcat容器时,我得到了
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 15 more Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory SEVERE: Error deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/cookpot java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cookpot]] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:898) at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:130) at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:153) at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:142) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:869) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/examples Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/host-manager Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/CookPot Jul 14, 2014 1:49:02 PM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/CookPot/WEB-INF/lib/tomcat-embed-core-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class Jul 14, 2014 1:49:02 PM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/CookPot/WEB-INF/lib/tomcat-embed-el-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class Jul 14, 2014 1:49:06 PM org.apache.catalina.core.ContainerBase addChildInternal SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CookPot]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895) at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:130) at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:153) at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:142) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:869) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission java.awt.headless write) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323) at java.security.AccessController.checkPermission(AccessController.java:546) at java.lang.SecurityManager.checkPermission(SecurityManager.java:532) at java.lang.System.setProperty(System.java:727) at org.springframework.boot.SpringApplication.run(SpringApplication.java:263) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:130) at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:89) at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:51) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 15 more Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory SEVERE: Error deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/CookPot java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CookPot]] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:898) at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:130) at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:153) at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:142) at java.security.AccessController.doPrivileged(Native Method) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:869) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/ROOT Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/manager Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/docs Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/Cookpot Jul 14, 2014 1:49:06 PM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/Cookpot/WEB-INF/lib/tomcat-embed-core-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class Jul 14, 2014 1:49:06 PM org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/Cookpot/WEB-INF/lib/tomcat-embed-el-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class Jul 14, 2014 1:49:09 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-6350"] Jul 14, 2014 1:49:09 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-4350"] Jul 14, 2014 1:49:09 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 17529 ms
Spring Boot参考文档中的打包可执行jar和war文件一章指出:
要构建一个既可执行又可部署到外部容器的war文件,你需要将嵌入式容器的相关性标记为“已提供”,例如:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <!-- ... --> <packaging>war</packaging> <!-- ... --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <!-- ... --> </dependencies> </project>