【发布时间】:2016-10-23 14:02:18
【问题描述】:
我有一个 Spring 4 Web 应用程序 (webapp-module.war) 在 Eclipse 中使用 Java 8、tomcat 8 和 JavaConfig(无 web.xml)在本地工作和运行:
但是当我在远程 Ubuntu 服务器上部署到 tomcat 8(我在 eclipse 中本地使用的相同版本)时,我得到:
我验证了正确的主机和端口。日志中没有错误(/var/lib/tomcat8/logs/catalina.out)
Jun 21, 2016 10:32:44 PM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/webapp-module]
Jun 21, 2016 10:32:44 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat8/webapps/webapp-module.war
Jun 21, 2016 10:32:46 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 21, 2016 10:32:46 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/tomcat8/webapps/webapp-module.war has finished in 1,870 ms
root@vmi63860:/var/lib/tomcat8/logs#
访问日志包含:
root@vmi63860:/var/log/tomcat8# cat localhost_access_log.2016-06-22.txt
xx.xxx.xxx.xx - - [22/Jun/2016:22:36:00 +0200] "GET /webapp-module/ HTTP/1.1" 404 1040
xx.xxx.xxx.xx - - [22/Jun/2016:22:36:00 +0200] "GET /favicon.ico HTTP/1.1" 404 1034
xx.xxx.xxx.xx - - [22/Jun/2016:22:36:50 +0200] "GET /webapp-module/hello HTTP/1.1" 404 1050
其中 xx.xxx.xxx.xx 是我尝试在浏览器中访问 Web 应用程序的本地计算机的 IP。
我看了看: Spring Java Config: Tomcat deploy without web.xml 但它并没有真正提供解决方案。
我的项目详情如下:
来源
Config.java
@Configuration // Marks this class as configuration
// Specifies which package to scan
@ComponentScan("com.samples")
// Enables Spring's annotations
@EnableWebMvc
public class Config {
@Bean
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
}
WebInitializer.java
public class WebInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(Config.class);
ctx.setServletContext(servletContext);
Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
}
}
HelloController.java
@Controller
public class HelloController {
@RequestMapping("/")
public String home() {
return "index";
}
@RequestMapping("/hello")
public String showhello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
【问题讨论】:
-
检查是否在 localhost_access_log.*.txt 内的 tomcat logs 文件夹
-
不确定您的意思,但在尝试从浏览器访问 Web 应用程序后,我使用服务器上最新访问日志中的内容更新了问题。虽然没有显示任何错误
-
它们可能看起来像愚蠢的问题,但是名为 webapp-module 的战争文件吗?我想你在 Eclipse 中也在 tomcat 实例中运行它,tomcat 版本是否匹配?
-
你能检查远程服务器上的 Tomcat 管理器应用程序 (
/manager) 吗?如果是这样,您的应用程序/webapp-module是否显示为已部署?如果您无法访问/manager,请参阅stackoverflow.com/a/38794114/639520 -
您可以发布您的应用程序日志文件吗?可能是您在启动时遇到错误,因此应用程序从未启动。
标签: java eclipse spring spring-mvc tomcat