当前位置: 代码迷 >> Java Web开发 >> simple spring web maven 项目无法发布到tomcat下(404异常)
  详细解决方案

simple spring web maven 项目无法发布到tomcat下(404异常)

热度:1406   发布时间:2016-04-13 22:17:08.0
simple spring web maven 项目无法发布到tomcat下(404错误)
开发环境:sts
服务器:tomcat8插件
项目文件结构:maven结构

问题:新建simple spring web maven项目后,在pom.xml上点[maven install..]下载各种jar包后,写了个helloworld的class以及各种.xml配置完成后,在项目名上点击[Run as..]后,把项目加载到tomcat8的插件上。在IE输入地址后,报404的错误。
          tomcat发布信息:
                                      十月 05, 2014 11:38:53 下午 org.apache.catalina.core.AprLifecycleListener init
                                       信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: 
                                      十月 05, 2014 11:38:54 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
           警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:simpleProject' did not find a matching property.
十月 05, 2014 11:38:55 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-nio-8080"]
十月 05, 2014 11:38:56 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
十月 05, 2014 11:38:56 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-nio-8009"]
十月 05, 2014 11:38:56 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
信息: Using a shared selector for servlet write/read
十月 05, 2014 11:38:56 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 4060 ms
十月 05, 2014 11:38:56 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
十月 05, 2014 11:38:56 下午 org.apache.catalina.core.StandardEngine startInternal
息: Starting Servlet Engine: Apache Tomcat/8.0.11
十月 05, 2014 11:38:57 下午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [217] milliseconds.
十月 05, 2014 11:38:57 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8080"]
十月 05, 2014 11:38:57 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-8009"]
十月 05, 2014 11:38:57 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 1174 ms

          奇怪的是,新建spring MVC project后,里面有些自动生成的simple source以及配置,发布到tomcat8下就可以正常访问。
          tomcat发布信息:
--------**********************************同上**********************************----------
--------↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓下面是多出来的内容,貌似项目被正常加载↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓----------

信息: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sun Oct 05 23:41:22 CST 2014];  root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root- context.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in  org.springframework.beans.factory.support.DefaultListableBeanFactory@13df422: defining beans []; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 827 ms
十月 05, 2014 11:41:22 下午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Sun  Oct 05 23:41:22 CST 2014]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB- INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-250 'javax.annotation.ManagedBean' found and supported for component  scanning
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component  scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for  autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in  org.springframework.beans.factory.support.DefaultListableBeanFactory@53d1c4: defining beans 。。。。。。
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "。。。。
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler  'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 1325 ms
十月 05, 2014 11:41:24 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-8080"]
十月 05, 2014 11:41:24 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-nio-8009"]
十月 05, 2014 11:41:24 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 6716 ms

--------↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑下面是多出来的内容,貌似项目被正常加载↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑----------

 从上面的信息来看,貌似我第一个项目就没有被tomcat所加载。
请问这是什么原因?有人碰到过类似的问题吗?


------解决思路----------------------
我也是有这个问题,刚刚解决了
应该是你的项目web部署组件没有配置好
打开你的项目属性,找到其中的 web deployment assembly 这个标签
然后你需要在里面把你的web根路径和jar包路径添加进去,比如/src/main/webapp Maven lib 等
这样你再部署到TOMCAT上应该就可以了。