Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在dispatcher servlet.xml中导入上下文文件_Java_Spring_Spring Mvc_Jakarta Ee - Fatal编程技术网

Java 如何在dispatcher servlet.xml中导入上下文文件

Java 如何在dispatcher servlet.xml中导入上下文文件,java,spring,spring-mvc,jakarta-ee,Java,Spring,Spring Mvc,Jakarta Ee,我创建了一个maven多模块项目,它们是MVCLayer、ServiceLayer和DAOLayer 在DAOLayer中,我在src/main/resources下有applicationContext.xml,如下所示 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.s

我创建了一个maven多模块项目,它们是MVCLayer、ServiceLayer和DAOLayer

在DAOLayer中,我在src/main/resources下有applicationContext.xml,如下所示

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

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/DB.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <!-- <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" /> -->
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>

      <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <import resource="classpath*:/applicationContext.xml"/>
    <!--   <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>DB.properties</value>
        </property>
    </bean>  --> 

    <!--  <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" />
    </bean>  -->

    <!--  <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>  -->

     <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.sharique.controller" />
    <mvc:annotation-driven />
    <import resource="classpath*:/serviceContext.xml"/>



    <bean id="ViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>Roomies</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>MVCLayer</artifactId>

    <packaging>war</packaging>
    <name>MVCLayer Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.servlet.jsp.jstl</artifactId>
            <version>1.2.1</version>
            <exclusions>
                <!-- jstl-api was adding selvlet-api 2.5 and jsp-api -->
                <exclusion>
                    <artifactId>jstl-api</artifactId>
                    <groupId>javax.servlet.jsp.jstl</groupId>
                </exclusion>
            </exclusions>
        </dependency>

         <dependency>
            <groupId>com.test</groupId>
            <artifactId>ServiceLayer</artifactId>
            <version>0.0.1-SNAPSHOT</version>           
        </dependency>

    </dependencies>
    <build>
        <finalName>MVCLayer</finalName>
    </build>
</project>

/DB.properties
${HIBERNATE.DAILECT}
${HBM2DDL.AUTO.UPDATE}
${HIBERNATE.SHOW_SQL}
在ServiceLayer中,serviceContext.xml位于src/main/resources下,如下所示

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

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/DB.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <!-- <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" /> -->
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>

      <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <import resource="classpath*:/applicationContext.xml"/>
    <!--   <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>DB.properties</value>
        </property>
    </bean>  --> 

    <!--  <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" />
    </bean>  -->

    <!--  <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>  -->

     <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.sharique.controller" />
    <mvc:annotation-driven />
    <import resource="classpath*:/serviceContext.xml"/>



    <bean id="ViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>Roomies</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>MVCLayer</artifactId>

    <packaging>war</packaging>
    <name>MVCLayer Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.servlet.jsp.jstl</artifactId>
            <version>1.2.1</version>
            <exclusions>
                <!-- jstl-api was adding selvlet-api 2.5 and jsp-api -->
                <exclusion>
                    <artifactId>jstl-api</artifactId>
                    <groupId>javax.servlet.jsp.jstl</groupId>
                </exclusion>
            </exclusions>
        </dependency>

         <dependency>
            <groupId>com.test</groupId>
            <artifactId>ServiceLayer</artifactId>
            <version>0.0.1-SNAPSHOT</version>           
        </dependency>

    </dependencies>
    <build>
        <finalName>MVCLayer</finalName>
    </build>
</project>

在MVCLayer中,WEB-INF下的MVC-Dispatcher-servlet.xml如下所示

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

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/DB.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <!-- <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" /> -->
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>

      <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <import resource="classpath*:/applicationContext.xml"/>
    <!--   <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>DB.properties</value>
        </property>
    </bean>  --> 

    <!--  <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" />
    </bean>  -->

    <!--  <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>  -->

     <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.sharique.controller" />
    <mvc:annotation-driven />
    <import resource="classpath*:/serviceContext.xml"/>



    <bean id="ViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>Roomies</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>MVCLayer</artifactId>

    <packaging>war</packaging>
    <name>MVCLayer Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.servlet.jsp.jstl</artifactId>
            <version>1.2.1</version>
            <exclusions>
                <!-- jstl-api was adding selvlet-api 2.5 and jsp-api -->
                <exclusion>
                    <artifactId>jstl-api</artifactId>
                    <groupId>javax.servlet.jsp.jstl</groupId>
                </exclusion>
            </exclusions>
        </dependency>

         <dependency>
            <groupId>com.test</groupId>
            <artifactId>ServiceLayer</artifactId>
            <version>0.0.1-SNAPSHOT</version>           
        </dependency>

    </dependencies>
    <build>
        <finalName>MVCLayer</finalName>
    </build>
</project>

org.springframework.web.servlet.view.JstlView
/WEB-INF/views/
.jsp
Sp在所有这些配置之后,当我从eclipse在tomcat中运行项目MVCLayer时,我得到了这个错误

严重:为servlet MVC Dispatcher分配异常 java.io.FileNotFoundException:无法打开ServletContext资源 [/DB.properties]位于 org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141) 在 org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143) 在 org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98) 在 org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175) 在 org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156) 在 org.springframework.beans.factory.config.propertyresourceConfiger.postProcessBeanFactory(propertyresourceConfiger.java:80) 在 org.springframework.context.support.postprocessorregistrationlegate.invokeBeanFactoryPostProcessors(postprocessorregistrationlegate.java:265) 在 org.springframework.context.support.postprocessorregistrationlegate.invokeBeanFactoryPostProcessors(postprocessorregistrationlegate.java:162) 在 org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) 在 org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) 在 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629) 在 org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677) 在 org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548) 在 org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) 在 org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 位于javax.servlet.GenericServlet.init(GenericServlet.java:160) org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1189) 在 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103) 在 org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:813) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 在 org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 位于java.util.concurrent.ThreadPoolExecutor.runWorker(未知源) 位于java.util.concurrent.ThreadPoolExecutor$Worker.run(未知源) 位于java.lang.Thread.run(未知源)

当我通过创建main类从ServiceLayer执行crud操作时,它工作正常,但每当我运行MVCLayer时,就会出现此错误 因此,请帮助我如何配置它

MVCLayer pom.xml如下所示

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

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/DB.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <!-- <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" /> -->
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>

      <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.sharique" />
    <tx:annotation-driven />
    <import resource="classpath*:/applicationContext.xml"/>
    <!--   <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>DB.properties</value>
        </property>
    </bean>  --> 

    <!--  <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
        <property name="driverClassName" value="${JDBC.DRIVERCLASSNAME}" />
        <property name="url" value="${JDBC.URL}" />
        <property name="username" value="${USERNAME}" />
        <property name="password" value="${PASSWORD}" />
        <property name="initialSize" value="2" /> <property name="maxActive" 
            value="5" />
    </bean>  -->

    <!--  <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.sharique.domainObjects" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${HIBERNATE.DAILECT}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM2DDL.AUTO.UPDATE}</prop>
                <prop key="hibernate.show_sql">${HIBERNATE.SHOW_SQL}</prop>
            </props>
        </property>
    </bean>  -->

     <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
    p:sessionFactory-ref="sessionFactory"></bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.sharique.controller" />
    <mvc:annotation-driven />
    <import resource="classpath*:/serviceContext.xml"/>



    <bean id="ViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.JstlView</value>
        </property>
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>
<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>Roomies</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>MVCLayer</artifactId>

    <packaging>war</packaging>
    <name>MVCLayer Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.servlet.jsp.jstl</artifactId>
            <version>1.2.1</version>
            <exclusions>
                <!-- jstl-api was adding selvlet-api 2.5 and jsp-api -->
                <exclusion>
                    <artifactId>jstl-api</artifactId>
                    <groupId>javax.servlet.jsp.jstl</groupId>
                </exclusion>
            </exclusions>
        </dependency>

         <dependency>
            <groupId>com.test</groupId>
            <artifactId>ServiceLayer</artifactId>
            <version>0.0.1-SNAPSHOT</version>           
        </dependency>

    </dependencies>
    <build>
        <finalName>MVCLayer</finalName>
    </build>
</project>

4.0.0
com.test
室友
0.0.1-快照
MVCLayer
战争
MVCLayer Maven Webapp
http://maven.apache.org
朱尼特
朱尼特
3.8.1
测试
javax.servlet.jsp.jstl
javax.servlet.jsp.jstl-api
1.2.1
org.glassfish.web
javax.servlet.jsp.jstl
1.2.1
JSTLAPI
javax.servlet.jsp.jstl
com.test
服务层
0.0.1-快照
MVCLayer

类路径添加到项目中似乎有问题 也可以将导入放在WEB-INF或WEB.xml中 这样做


上下文配置位置