我在Converting a Spring Boot JAR Application to a WAR using Maven和Spring Boot Docs中做了修改.
部署顺利(日志很好,没有错误),并查看Tomcat管理,我看到我的应用程序部署.但是,当我尝试访问http://localhost:8080/sophia/users卷曲我得到404.
任何帮助深表感谢.
更新:
这是我的日志:
Netbeans的:
NetBeans: Deploying on Apache Tomcat 8.0.17
profile mode: false
debug mode: false
force redeploy: trueIn-place deployment at /home/bugz/workspace/pdcore/sophiaserver/target/sophia-server-1.0.0-SNAPSHOT
Deployment is in progress…
deploy?config=file%3A%2Ftmp%2Fcontext1845402702541504208.xml&path=/sophia
OK – Deployed application at context path /sophia
Start is in progress…
start?path=/sophia
OK – Started application at context path /sophia
Tomcat的:
INFO 10:47:52:703 org.springframework.boot.context.embedded.ServletRegistrationBean – Mapping servlet: ‘dispatcherServlet’ to [/sophia/*]
INFO 10:47:54:042 org.springframework.boot.SpringApplication – Started application in 8.285 seconds (JVM running for 12087.301)
22-Jan-2015 10:47:54.060 INFO [http-nio-8080-exec-99] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor /home/bugz/workspace/server/apache-tomcat-8.0.17/conf/Catalina/localhost/sophia.xml has finished in 12,091 ms
而在sophia.xml中为Catalina本地主机:
<?xml version="1.0" encoding="UTF-8"?> <Context antiJARLocking="true" docBase="/home/bugz/workspace/pdcore/sophiaserver/target/sophia-server-1.0.0-SNAPSHOT" path="/sophia"/>
我试过访问
> http://localhost:8080/sophia/users
> http://localhost:8080/sophia-server-1.0.0-SNAPSHOT/users(WAR的名称)
第一个返回404,但是使用CORS过滤器的CORS信息.第二个返回404没有CORS信息(指示应用程序已启动并被配置,但我似乎没有访问控制器).
解决方法
第一个是应用程序部署的基本URL,在您的情况下是/ sophia.
第二个是在你的情况下是/ sohpia / *的DispatcherServlet的servlet映射.
第三个是DispatcherServlet中的控制器映射,在你的例子中是/ users.
所有这些组合都会创建URL / sophia / sophia / users.
作为WAR的部署之间的区别是,当您作为一个jar运行时,您将包含一个单独的URL来部署,默认情况下部署到/(根).
您可以将/ sophia作为server.context-path放在application.properties中并将DispatcherServlet映射到/ *或/.这将在两种情况下为您提供所需的URL(和预期).