27

किया जा सका। जब मैं इसे शुरू करने के लिए truy, यह संदर्भ intialize करने के लिए सफल नहीं करता है:मेरे आवेदन मैं <em>ग्रहण Maven</em> वेब परियोजना मैं कहाँ का उपयोग <em>वसंत MVC</em> और <em>स्प्रिंग सुरक्षा</em> नहीं खुला ServletContext संसाधन

Could not open ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]

अधिक जानकारी नीचे:


यह मेरा web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
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"> 

<display-name>Web Manager</display-name> 
<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
      /WEB-INF/spring/app-config.xml, /WEB-INF/spring/security-config.xml 
    </param-value> 
</context-param> 

<!-- Spring MVC --> 
<servlet> 
    <servlet-name>spring-dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>spring-dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

<!-- Spring Security --> 
<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> 

यह मेरा app-config.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 

<!-- Scans the classpath of this application for @Components to deploy as beans --> 
<context:component-scan base-package="fr.tessa.webmanager" /> 


<!-- Configures the @Controller programming model --> 
<mvc:annotation-driven /> 

<!-- misc --> 
<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" 
     value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

<!-- Configure the multipart resolver --> 
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
    <!-- one of the properties available; the maximum file size in bytes --> 
    <property name="maxUploadSize" value="1000000" /> 
</bean> 

<!-- Configures Hibernate - Database Config --> 
<import resource="dbconfig/validationdb-config.xml" /> 
<import resource="dbconfig/db-config.xml" /> 


इस मेरे पास है जब मैं आवेदन शुरू मेरी security-config.xml

<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
       http://www.springframework.org/schema/security 
       http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

<http use-expressions="true"> 
    <intercept-url pattern="/welcome*" access="ROLE_USER" /> 
    <form-login login-page="/login" default-target-url="/welcome" 
     authentication-failure-url="/loginfailed" /> 
    <logout logout-success-url="/logout" /> 
</http> 
<authentication-manager> 
    <authentication-provider> 
    <user-service> 
     <user name="mkyong" password="123456" authorities="ROLE_USER" /> 
    </user-service> 
    </authentication-provider> 
</authentication-manager> 
</beans:beans> 

मेरी समस्या है त्रुटि की तरह

Infos: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml] 
févr. 19, 2013 10:50:09 AM org.springframework.web.servlet.FrameworkServlet initServletBean 
Grave: Context initialization failed 
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml] 
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) 
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) 
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) 
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) 
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) 
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) 
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131) 
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436) 
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588) 
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645) 
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508) 
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449) 
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133) 
at javax.servlet.GenericServlet.init(GenericServlet.java:212) 
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) 
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993) 
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350) 
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659) 
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) 
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785) 
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) 
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445) 
at org.apache.catalina.startup.Embedded.start(Embedded.java:825) 
at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558) 
at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255) 
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml] 
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140) 
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) 
... 48 more 

यह कहना है कि यह /WEB-INF/spring-dispatcher-servlet.xml नहीं मिल रहा, लेकिन मैं web.xml में रख did't, मेरे विन्यास फाइल Spring reference doc से app-config.xml

उत्तर

76

उद्धरण है:

एक DispatcherServlet के प्रारंभ होने पर, वसंत MVC एक के लिए लग रहा है अपने वेब अनुप्रयोग का वेब-INF निर्देशिका में फ़ाइल का नाम [सर्वलेट-नाम] -servlet.xml और सेम वहाँ परिभाषित बनाता है ...

आपका सर्वलेट spring-dispatcher कहा जाता है, तो यहके लिए लग रहा हैआपको यह सर्वलेट कॉन्फ़िगरेशन होना चाहिए, और वहां वेब से संबंधित बीन्स को परिभाषित करना होगा (जैसे नियंत्रक, रिज़ॉल्यूशन देखें, आदि)। ग्लोबल एप्लिकेशन संदर्भ में सर्वलेट संदर्भों के संबंध में स्पष्टीकरण के लिए लिंक किए गए दस्तावेज़ देखें (जो आपके मामले में app-config.xml है)।

एक और बात, अगर आप सर्वलेट config xml का नामकरण परंपरा पसंद नहीं है, तो आप अपने config स्पष्ट रूप से निर्दिष्ट कर सकते हैं:

<servlet> 
    <servlet-name>spring-dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
+1

धन्यवाद Zagyi, मैं संदर्भ परम से "/WEB-INF/spring/app-config.xml" हटा दिया और मैं सर्वलेट init परम में outed और यह काम, तो +1 आपकी प्रतिक्रिया :-) – user820688

1

आप एक जावा विन्यास के साथ इस त्रुटि हो रही है, तो यह है

: निर्माता आर्ग के रूप में संदर्भ जोड़कर

AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); 
ctx.register(WebConfig.class); 

ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher", 
    new DispatcherServlet()); // <-- no constructor args! 
dispatcher.setLoadOnStartup(1); 
dispatcher.addMapping("/*"); 

इसे ठीक करें: यदि आप DispatcherServlet निर्माता के लिए आवेदन के संदर्भ में पारित करने के लिए भूल जाते हैं क्योंकि आम तौर पर

+0

इस के लिए वास्तव में मेरा मामला – tsayen

+0

ओएमएफजी था, 4 दिन और इससे मदद मिली। धन्यवाद। सिर्फ रिकार्ड के लिए। मानक वसंत बूट ऐप पर वाइल्डफ्लाई 10 openshift परिनियोजन के साथ मदद करता है। इसके अलावा Maven javax.servlet javax.servlet-api प्रदान की में सेट करने का प्रयास –

0

सुनिश्चित करें कि युद्ध के दौरान pom.xml में आपके मेवेन युद्ध प्लगइन ब्लॉक में सभी फ़ाइलें (विशेष रूप से एक्सएमएल फाइलें) शामिल हैं। लेकिन आपको .java फ़ाइलों को शामिल करने की आवश्यकता नहीं है।

   <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.5</version>     
       <configuration>  
         <webResources> 
         <resources> 
          <directory>WebContent</directory> 
          <includes> 
           <include>**/*.*</include><!--this line includes the xml files into the war, which will be found when it is exploded in server during deployment --> 
          </includes> 
          <excludes> 
           <exclude>*.java</exclude> 
          <excludes> 
         </resources>       
         </webResources>    
        <webXml>WebContent/WEB-INF/web.xml</webXml>          
       </configuration> 
      </plugin> 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^