java吧 关注:1,240,217贴子:12,714,306
  • 2回复贴,共1

SPRING报错提示找不到applicationcontext但是能正常使用

只看楼主收藏回复

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
提示不存在,但是用 ApplicationContext context= new ClassPathXmlApplicationContext("applicationContext.xml");可以提取到
applicationContext.xml是放在src源文件夹下面的,web.xml里的配置是
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
也试过classpath:applicationContext.xml,也不行
另外在jsp中使用了struts标签后,运行时会在后台输出web.xml里的内容
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<async-supported>false</async-supported>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<async-supported>false</async-supported>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
<cookie-config>
</cookie-config>
</session-config>
<mime-mapping>
<extension>fh7</extension>
<mime-type>image/x-freehand</mime-type>
</mime-mapping>
<mime-mapping>
<extension>fh5</extension>
<mime-type>image/x-freehand</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xhvml</extension>
<mime-type>application/xv+xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>fh4</extension>
<mime-type>image/x-freehand</mime-type>
</mime-mapping>
<mime-mapping>
<extension>x3db</extension>
<mime-type>model/x3d+binary</mime-type>
</mime-mapping>
还有很多类似这样的内容,因为太长不截取了,现在发现如果不使用struts2标签就不会输出这些,希望高手能告诉我是怎么回事


IP属地:江苏1楼2015-02-15 18:20回复
    struts.xml的配置
    <struts>
    <!-- 详细信息,开发阶段打开 -->
    <constant name="struts.devMode" value="true" />
    <!-- 集成spring -->
    <constant name="struts.objectFactory" value="spring" />
    <package name="MyPackage" extends="struts-default">
    <global-results>
    <result name="error">/error.jsp</result>
    </global-results>
    </package>
    <package name="Student" namespace="/student" extends="MyPackage">
    <action name="addstudent" method="add" class="StudentAction">
    <result name="success">/index.jsp</result>
    <result name="register">/student/addstudent.jsp</result>
    <result name="input">/student/addstudent.jsp</result>
    </action>
    </package>
    <package name="visit" namespace="" extends="MyPackage">
    <action name="login" method="login" class="VisitAction">
    <result name="studentlogin">/student/default1.jsp</result>
    <result name="teacherlogin">/teacher/default2.jsp</result>
    <result name="adminlogin">/admin/default3.jsp</result>
    <result name="login">/index.jsp</result>
    <result name="input">/index.jsp</result>
    </action>
    </package>
    <!-- <include file="example.xml"/> -->
    <!-- Add packages here -->
    </struts>


    IP属地:江苏2楼2015-02-15 18:21
    回复
      applicationContext的配置
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="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">
      <!-- 配置会话工厂-->
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="configLocation"><value>classpath:hibernate.cfg.xml</value></property>
      </bean>
      <!-- 扫描注解 -->
      <context:component-scan base-package="com.njupt"/>
      <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
      <property name="sessionFactory" ref="sessionFactory" />
      </bean>
      <!-- 配置事务管理器bean,使用HibernateTransactionManager事务管理器 -->
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <!-- 为事务管理器注入sessionFactory" -->
      <property name="sessionFactory" ref="sessionFactory" />
      </bean>
      <!-- 配置事务拦截器Bean -->
      <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor" >
      <!-- 为事务拦截器bean注入一个事物管理器 -->
      <property name="transactionManager" ref="transactionManager"></property>
      <property name="transactionAttributes">
      <!-- 定义事务传播属性 -->
      <props>
      <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
      <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
      <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
      <prop key="save*">PROPAGATION_REQUIRED</prop>
      <prop key="add*">PROPAGATION_REQUIRED</prop>
      <prop key="update*">PROPAGATION_REQUIRED</prop>
      <prop key="remove*">PROPAGATION_REQUIRED</prop>
      <prop key="*">PROPAGATION_REQUIRED</prop>
      </props>
      </property>
      </bean>
      <bean
      class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="beanNames">
      <list>
      <value>*Dao</value>
      </list>
      </property>
      <property name="interceptorNames">
      <list>
      <value>transactionInterceptor</value>
      </list>
      </property>
      </bean>
      <bean id="Dao" class="com.njupt.dao.impl.DaoImpl">
      <property name="hibernateTemplate" >
      <ref bean="hibernateTemplate"/>
      </property>
      </bean>
      <bean id="StudentService" class="com.njupt.service.impl.StudentServiceImpl" >
      <property name="Dao" >
      <ref bean="Dao"/>
      </property>
      </bean>
      <bean id="StudentAction" class="com.njupt.action.StudentAction" scope="prototype">
      <property name="studentService">
      <ref bean="StudentService"/>
      </property>
      </bean>
      <bean id="VisitAction" class="com.njupt.action.VisitAction" scope="prototype">
      <property name="studentService">
      <ref bean="StudentService"/>
      </property>
      </bean>
      </beans>


      IP属地:江苏3楼2015-02-15 18:22
      回复