我在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. Spring Tool Suite缺少Spring MVC項目模板
- 2. SpringSource工具套件缺少Spring MVC的項目模板
- 3. java.lang.LinkageError:ClassCastException:在Spring MVC項目中
- 4. iOS項目中缺少AddressBook.framework
- 5. 缺少'android項目'
- 6. 項目中缺少guiddef.h
- 7. 缺少SSDT項目
- 8. WebForm項目到MVC - 缺少上下文菜單項目
- 9. Spring MVC HandlerInterceptorAdapter缺少slf4j Logback跟蹤ID
- 10. Spring MVC的多個requestmapping,缺少requestparam
- 11. 在PHP中使用simpleXML缺少項目
- 12. 在Android項目中缺少android類
- 13. 在.NET項目中缺少系統DLL
- 14. 在Xcode 4.2中缺少項目模板
- 15. 在項目中缺少database.yml文件
- 16. 在Visual Studio 2015中缺少Web項目
- 17. 在spring-boot項目中使用spring mvc xml項目
- 18. 獲取錯誤缺少工件spring-web:org.springframework在Spring MVC
- 19. 缺少項目亞型F#項目
- 20. eclipse -restore缺少項目
- 21. DbSet:缺少添加項目
- 22. VC6項目缺少msvcp71d.dll?
- 23. 缺少工具箱項目
- 24. 缺少org.apache.commons.dbcp包Maven項目
- 25. Settings.bundle在iOS項目中缺少Root.plist和其他項目;
- 26. 我在Spring MVC項目中遇到NullPointerException?
- 27. Spring 4.1.1中缺少org.springframework.scheduling.quartz.JobDetailBean
- 28. Spring 4中缺少SpringBeanJobFactory
- 29. STS中缺少Spring AOP庫
- 30. swift ios paypal sdk,項目中缺少settings.bundle