部署一个简单的Spring MVC应用程序后出错404(没有web.xml) [英] Error 404 after deploying a simple Spring MVC app (without web.xml)

查看:96
本文介绍了部署一个简单的Spring MVC应用程序后出错404(没有web.xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想完全基于注释学习一些Spring MVC的基础知识。我从本教程

I want to learn some basics of Spring MVC based fully on annotations. I started with this tutorial.

克隆存储库后

hg clone https://bitbucket.org/arnelism/snoutbook

并构建 war file

mvn package

我只是将 war 文件复制到来部署应用程序webapps 我的Apache Tomcat 7.0.12实例的目录。我正在停止并启动服务器。

I am deploying the app by simply copying the war file to the webapps directory of my Apache Tomcat 7.0.12 instance. I am stopping and starting the server.

INFORMATION: Starting Servlet Engine: Apache Tomcat/7.0.12
Sep 12, 2014 3:37:18 PM org.apache.catalina.startup.HostConfig deployWAR
INFORMATION: Deploying web application archive Snoutbook-1.0.0-SNAPSHOT.war
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory docs
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory examples
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory host-manager
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory manager
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMATION: Deploying web application directory ROOT
Sep 12, 2014 3:37:27 PM org.apache.coyote.AbstractProtocolHandler start
INFORMATION: Starting ProtocolHandler ["http-bio-8080"]
Sep 12, 2014 3:37:27 PM org.apache.coyote.AbstractProtocolHandler start
INFORMATION: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 12, 2014 3:37:27 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 8826 ms

不幸的是,在此操作后,我收到错误404,显示页面。

Unfortunately after this operation I am receiving the error 404 by displaying the page.

http://localhost:8080/Snoutbook-1.0.0-SNAPSHOT/

我一直在寻找超过2小时的解决方案,但却找不到原因。有人有类似的问题吗?

I have been looking for a solution for over 2 hours and have not been able to find the cause. Did somebody have a similar issue?

我尝试使用最新的Tomcat版本 Apache的Tomcat的8.0.12 。问题依然存在。但是,在部署Web应用程序时,控制台中会打印更多信息。

I tried with the newest Tomcat version apache-tomcat-8.0.12. The problem persists. There is however more info printed in the console while deploying the web app.


12-Sep-2014 17:13:20.038 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployWAR Deploying web application archive D:\Users\b21090094\apac
he-tomcat-8.0.12\webapps\Snoutbook-1.0.0-SNAPSHOT.war
12-Sep-2014 17:13:23.132 INFO [localhost-startStop-1] org.apache.catalina.util.S
essionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for s
ession ID generation using [SHA1PRNG] took [255] milliseconds.
12-Sep-2014 17:13:23.169 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.FrameworkServlet.initServletBean FrameworkServlet 'dispatcher': initializa
tion started
12-Sep-2014 17:13:23.182 INFO [localhost-startStop-1] org.springframework.contex
t.support.AbstractApplicationContext.prepareRefresh Refreshing WebApplicationCon
text for namespace 'dispatcher-servlet': startup date [Fri Sep 12 17:13:23 CEST
2014]; root of context hierarchy
12-Sep-2014 17:13:23.278 INFO [localhost-startStop-1] org.springframework.contex
t.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters
JSR-250 'javax.annotation.ManagedBean' found and supported for component scannin
g
12-Sep-2014 17:13:23.281 INFO [localhost-startStop-1] org.springframework.web.co
ntext.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions Register
ing annotated classes: [class com.zeroturnaround.snoutbook.init.WebappConfigJpa]

12-Sep-2014 17:13:23.429 INFO [localhost-startStop-1] org.springframework.contex
t.annotation.ClassPathScanningCandidateComponentProvider.registerDefaultFilters
JSR-250 'javax.annotation.ManagedBean' found and supported for component scannin
g
12-Sep-2014 17:13:23.921 INFO [localhost-startStop-1] org.springframework.beans.
factory.support.DefaultListableBeanFactory.preInstantiateSingletons Pre-instanti
ating singletons in org.springframework.beans.factory.support.DefaultListableBea
nFactory@7169a1: defining beans [org.springframework.context.annotation.internal
ConfigurationAnnotationProcessor,org.springframework.context.annotation.internal
AutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequ
iredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnn
otationProcessor,org.springframework.context.annotation.internalPersistenceAnnot
ationProcessor,webappConfigJpa,org.springframework.context.annotation.Configurat
ionClassPostProcessor$ImportAwareBeanPostProcessor#0,addPetForm,snoutContoller,s
noutDao,org.springframework.aop.config.internalAutoProxyCreator,delegatingWebMvc
Configuration,requestMappingHandlerMapping,viewControllerHandlerMapping,beanName
HandlerMapping,resourceHandlerMapping,defaultServletHandlerMapping,requestMappin
gHandlerAdapter,mvcConversionService,mvcValidator,httpRequestHandlerAdapter,simp
leControllerHandlerAdapter,handlerExceptionResolver,proxyTransactionManagementCo
nfiguration,org.springframework.transaction.config.internalTransactionAdvisor,tr
ansactionAttributeSource,transactionInterceptor,transactionManager,entityManager
Factory,setupViewResolver,getDataSource]; root of factory hierarchy
12-Sep-2014 17:13:24.225 INFO [localhost-startStop-1] org.springframework.orm.jp
a.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory Buildi
ng JPA container EntityManagerFactory for persistence unit 'default'
12-Sep-2014 17:13:24.657 INFO [localhost-startStop-1] org.hibernate.annotations.
common.Version. HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

12-Sep-2014 17:13:24.676 INFO [localhost-startStop-1] org.hibernate.Version.logV
ersion HHH000412: Hibernate Core {4.1.2}
12-Sep-2014 17:13:24.681 INFO [localhost-startStop-1] org.hibernate.cfg.Environm
ent. HHH000206: hibernate.properties not found
12-Sep-2014 17:13:24.686 INFO [localhost-startStop-1] org.hibernate.cfg.Environm
ent.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
12-Sep-2014 17:13:24.772 INFO [localhost-startStop-1] org.hibernate.ejb.Ejb3Conf
iguration.configure HHH000204: Processing PersistenceUnitInfo [
        name: default
        ...]
12-Sep-2014 17:13:25.524 INFO [localhost-startStop-1] org.hibernate.service.jdbc
.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionP
rovider HHH000130: Instantiating explicit connection provider: org.hibernate.ejb
.connection.InjectedDataSourceConnectionProvider
12-Sep-2014 17:13:26.275 INFO [localhost-startStop-1] org.hibernate.dialect.Dial
ect. HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
12-Sep-2014 17:13:26.356 INFO [localhost-startStop-1] org.hibernate.engine.trans
action.internal.TransactionFactoryInitiator.initiateService HHH000268: Transacti
on strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFacto
ry
12-Sep-2014 17:13:26.374 INFO [localhost-startStop-1] org.hibernate.hql.internal
.ast.ASTQueryTranslatorFactory. HHH000397: Using ASTQueryTranslatorFactory

12-Sep-2014 17:13:26.498 INFO [localhost-startStop-1] . HV0000
01: Hibernate Validator 4.3.0.Final
12-Sep-2014 17:13:27.699 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/addP
et],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto
public java.lang.String com.zeroturnaround.snoutbook.controllers.AddPetForm.setu
pForm(org.springframework.ui.Model)
12-Sep-2014 17:13:27.700 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/addP
et],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto
 public java.lang.String com.zeroturnaround.snoutbook.controllers.AddPetForm.han
dleSubmit(com.zeroturnaround.snoutbook.form.PetForm,org.springframework.validati
on.BindingResult,org.springframework.web.bind.support.SessionStatus)
12-Sep-2014 17:13:27.701 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/pet/
{petId}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" ont
o public java.lang.String com.zeroturnaround.snoutbook.controllers.SnoutContolle
r.pet(java.lang.Long,org.springframework.ui.Model)
12-Sep-2014 17:13:27.702 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/owne
rs],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto pub
lic java.lang.String com.zeroturnaround.snoutbook.controllers.SnoutContoller.lis
tOwners(org.springframework.ui.Model)
12-Sep-2014 17:13:27.762 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.handler.AbstractUrlHandlerMapping.registerHandler Mapped URL path [/**] on
to handler of type [class org.springframework.web.servlet.resource.DefaultServle
tHttpRequestHandler]
12-Sep-2014 17:13:28.129 INFO [localhost-startStop-1] org.springframework.web.se
rvlet.FrameworkServlet.initServletBean FrameworkServlet 'dispatcher': initializa
tion completed in 4960 ms
12-Sep-2014 17:13:28.140 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployWAR Deployment of web application archive D:\Users\b21090094\
apache-tomcat-8.0.12\webapps\Snoutbook-1.0.0-SNAPSHOT.war has finished in 8,103
ms
12-Sep-2014 17:13:28.141 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\docs
12-Sep-2014 17:13:28.167 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\docs has finished in 26 ms
12-Sep-2014 17:13:28.168 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\examples
12-Sep-2014 17:13:28.537 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\examples has finished in 370 ms
12-Sep-2014 17:13:28.538 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\host-manager
12-Sep-2014 17:13:28.572 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\host-manager has finished in 34 ms
12-Sep-2014 17:13:28.573 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\manager
12-Sep-2014 17:13:28.633 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\manager has finished in 61 ms
12-Sep-2014 17:13:28.633 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deploying web application directory D:\Users\b21090
094\apache-tomcat-8.0.12\webapps\ROOT
12-Sep-2014 17:13:28.659 INFO [localhost-startStop-1] org.apache.catalina.startu
p.HostConfig.deployDirectory Deployment of web application directory D:\Users\b2
1090094\apache-tomcat-8.0.12\webapps\ROOT has finished in 26 ms
12-Sep-2014 17:13:28.663 INFO [main] org.apache.coyote.AbstractProtocol.start St
arting ProtocolHandler ["http-nio-8080"]
12-Sep-2014 17:13:28.676 INFO [main] org.apache.coyote.AbstractProtocol.start St
arting ProtocolHandler ["ajp-nio-8009"]
12-Sep-2014 17:13:28.682 INFO [main] org.apache.catalina.startup.Catalina.start
Server startup in 8701 ms

之后我仍然得到错误404.

After that I am still getting Error 404.

推荐答案

尝试使用 http:// localhost:8080 / Snoutbook-1.0.0-SNAPSHOT / owner

上传战争时文件到tomcat的webapp文件夹,默认情况下tomcat允许你使用war的名称访问webapp。然后当你看到 web app初始化程序 web.xml 的替代),它正在注册 DispatcherServlet 使用 / 映射。接下来,你看看控制器,它有 @RequestMapping 指向 / owner
因此,路径为:

When you upload war file to webapp folder of tomcat, by default tomcat let you access the webapp with the war's name. And then when you look at the web app initializer (the subtitute of web.xml), it's registering the DispatcherServlet with / mapping. Next, you look at the controller, it have @RequestMapping pointed to /owners. Hence, the path is:

host:port + war- name + servlet-mapping + controller-mapping

host:port + war-name + servlet-mapping + controller-mapping

等于

localhost:8080 / + Snoutbook- 1.0.0-SNAPSHOT / + / + 所有者

localhost:8080/ + Snoutbook-1.0.0-SNAPSHOT/ + / + owners

等于

http:// localhost:8080 / Snoutbook-1.0.0-SNAPSHOT / Owner

这篇关于部署一个简单的Spring MVC应用程序后出错404(没有web.xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆