我在Spring工具套件中创建了一个Spring mvc项目。我正在关注YouTube教程视频,视频的作者是指将一些文本添加到dispatcher-servlet.xml中,但是在创建Spring项目时并未创建dispatcher-servlet.xml。这是为什么?它可以被称为别的东西吗?在spring mvc项目中缺少dispatcher-servlet.xml
0
A
回答
0
我认为有几种方法可以创建简单的spring web项目。我知道的一些方式是:
从eclipse(STS)创建动态Web项目/并把春天lirary它。
形式STS文件/新建/ Maven项目(org.apache.maven.archetypes)/填写组ID,工件ID v.v ..
从STS文件/新建/ Spring项目/简单的Spring Web Maven的。
Spring Roo的命令
web mvc setup
不属于如何创建项目后,创建我们总是有文件的web.xml web.xml中的
内容类似这样
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<!-- The most important thing to understand is that there are 2 layers of application contexts,
and they each have default XML files to load beans from
1.Servlet Application Context
2.Root application context
-->
<display-name>Archetype Created Web Application</display-name>
<!--
The Each Spring DispatcherServlet defined in the web.xml file gets its own application context.
If there is a Root application context (i.e. if a ContextLoaderListener is defined), then
that will be the parent of the servlet context and the beans will be available for use in
the servlet context(s). By default, DispatcherServlet loads beans from the file
/WEB-INF/<servlet-name>-servlet.xml -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
<!--The Root application context is created
when you specify a ContextLoaderListener in your web.xml file. If you don't
specify a listener, then there will be no Root context (which is valid).
It allows you to define beans that will be available to all the servlet
contexts.REMEMBER: This context is OPTIONAL, and will only be created if
you specify a ContextLoaderListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml,
/WEB-INF/spring-database.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
</web-app>
声明
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
是dispatcher-servlet xml配置文件的位置。如果缺少此声明,则缺省值将是direcrory webapp(或WebContent)中的文件名dispatcher-servlet.xml。如果缺少dispatcher-servlet.xml,不用担心,只需在那里创建文件即可。我们可以把这个declation到web.xml文件如上
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/example/funny.xml</param-value>
</init-param>
认为它可以帮助
改变dispathcher servlet的XML配置文件的名称和位置相关问题
- 1. SpringSource工具套件缺少Spring MVC的项目模板
- 2. java.lang.LinkageError:ClassCastException:在Spring MVC项目中
- 3. iOS项目中缺少AddressBook.framework
- 4. 缺少'android项目'
- 5. 项目中缺少guiddef.h
- 6. 在Visual Studio 2015中缺少Web项目
- 7. 在Android项目中缺少android类
- 8. 获取错误缺少工件spring-web:org.springframework在Spring MVC
- 9. eclipse -restore缺少项目
- 10. DbSet:缺少添加项目
- 11. VC6项目缺少msvcp71d.dll?
- 12. 缺少工具箱项目
- 13. 缺少org.apache.commons.dbcp包Maven项目
- 14. Spring 4中缺少SpringBeanJobFactory
- 15. Spring 4.1.1中缺少org.springframework.scheduling.quartz.JobDetailBean
- 16. 我在Spring MVC项目中遇到NullPointerException?
- 17. swift ios paypal sdk,项目中缺少settings.bundle
- 18. iOS - Xcode 4项目中缺少文件
- 19. Eclipse项目中缺少.classpath文件
- 20. ASP.NET Core项目中缺少SqlDataAdapter
- 21. 缺少request.CreateResponse在vb.net Webapi项目
- 22. 部署项目中缺少项目依赖项
- 23. 安装ASP.NET MVC之后缺少项目模板2
- 24. ASP.NET MVC缺少htmlhelpers
- 25. Spring MVC演示项目
- 26. STS模板Spring MVC项目
- 27. 在VSIX项目上缺少Extensiblity项目模板
- 28. 在Eclipse中缺少“添加文件到黑莓项目”选项
- 29. Spring MVC - HTTP状态404错误。 web.xml中缺少任何东西
- 30. Spring MVC的项目不是在Eclipse