2014-10-18 4 views
0

Я создал проект весны mvc в весеннем костюме инструмента. Я следую видеоролику YouTube, и автор видео ссылается на некоторый текст, добавленный в dispatcher-servlet.xml, но dispatcher-servlet.xml не был создан, когда я создал проект Spring. Почему это? Можно ли это назвать другим?Отсутствует dispatcher-servlet.xml в весенний проект mvc

ответ

0

Я думаю, что существует несколько способов создать простой проект весеннего веб-сайта. Некоторые пути я знаю:

  1. От затмения (STS) создания динамических веб-проекта/и поставить пружины lirary к нему.

  2. Форма STS Файл/Новый проект/Maven (org.apache.maven.archetypes)/заливкой идентификатор группы, артефакт ID v.v ..

  3. От STS File/New/Spring Project/Simple Spring Web Maven.

  4. 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> 

- это положение конфигурационного файла диспетчера-сервлета xml. Если отсутствует это объявление, по умолчанию будет имя файла dispatcher-servlet.xml в адресной папке webapp (или WebContent). Если отсутствует dispatcher-servlet.xml, не волнуйтесь, просто создайте файл там. Мы можем изменить имя и положение dispathcher сервлета XML-файла конфигурации с помощью этого положить declation в web.xml файл, как описано выше

<init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>WEB-INF/example/funny.xml</param-value> 
</init-param> 

думаю, что это могло бы помочь

Смежные вопросы