Java 找不到app-context.xml

Java 找不到app-context.xml,java,maven,jakarta-ee,netbeans,Java,Maven,Jakarta Ee,Netbeans,这是“JAVA错误转向”的下一期 所以我有这个应用程序,它编译得很好。我在这里读到一个线程,并将我的app-context.xml和application-context.xml移到主目录下的SOURCES文件夹中,而不是Web Inf/目录中 我得到这个错误: [ Thread-22] ContextLoader ERROR Context initialization failed org.springfra

这是“JAVA错误转向”的下一期

所以我有这个应用程序,它编译得很好。我在这里读到一个线程,并将我的app-context.xml和application-context.xml移到主目录下的SOURCES文件夹中,而不是Web Inf/目录中

我得到这个错误:

[                     Thread-22] ContextLoader                  ERROR      Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException     parsing XML document from class path resource [app-context.xml]; nested     exception is java.io.FileNotFoun
dException: class path resource [app-context.xml] cannot be opened because     it does not exist
以下是我的WEB.XML文件部分:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/servlet-context.xml classpath:app-context.xml</param-value>
</context-param>
<context-param>
    <param-name>applicationContextLocation</param-name>
    <param-value>/WEB-INF/source/applicationContext.xml classpath:applicationContext.xml</param-value>
</context-param>
以下是app-context.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:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/aop     
   http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/tx     
   http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/context/spring-context-3.0.xsd"
   default-autowire="byName">

<tx:annotation-driven classpath="/Web Pages/" />

<!-- Scans within the base package of the application for @Components to
     configure as beans -->
<context:component-scan base-package="com.ccur.mdimgmtsys" />


<!-- Drives transactions using local JPA APIs -->
    <bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
 </bean>

 <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="forceDatabase" />
 </bean>

 <bean
 class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPost
 Processor" />

<bean id="forceService" class="com.force.sdk.connector.ForceServiceConnector">
    <property name="connectionName" value="forceDatabase"/>
</bean>

    <!--bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/jdbc.properties" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" /-->

<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->


</beans>

谢谢


Peter

包括上下文名称空间(来自私人项目的示例):


(注意:xmlns:context=“…”和之后的xsi:schemaLocation=“…”

我既没有检查您的spring版本,也没有检查最新版本,但不久前这一版本对我有效;) 请将其更新到您所需的版本

<?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:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
   http://www.springframework.org/schema/aop     
   http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/tx     
   http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/context/spring-context-3.0.xsd"
   default-autowire="byName">

<tx:annotation-driven classpath="/Web Pages/" />

<!-- Scans within the base package of the application for @Components to
     configure as beans -->
<context:component-scan base-package="com.ccur.mdimgmtsys" />


<!-- Drives transactions using local JPA APIs -->
    <bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
 </bean>

 <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="forceDatabase" />
 </bean>

 <bean
 class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPost
 Processor" />

<bean id="forceService" class="com.force.sdk.connector.ForceServiceConnector">
    <property name="connectionName" value="forceDatabase"/>
</bean>

    <!--bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/jdbc.properties" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" /-->

<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->


</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-3.2.xsd">