说明 资源路径 位置类型 与未绑定的元素类型关联的属性"p:sessionFactory-ref" "beans:bean"的前缀"p"



我正在使用Spring开发一个web应用程序,我现在正在使用这个Spring实现hibernate,当我创建servlet-context.xml文件时,我得到了上面的错误(描述资源路径位置类型前缀"p"属性"p:sessionFactory-ref"与元素类型"beans:bean"不绑定),我谷歌它,但找不到任何积极的答案。这是我的servlet-context.xml文件:我在文件中放了一个关于错误位置的注释。

 <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/mvc"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            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">
        <!-- DispatcherServlet Context: defines this servlet's request-processing 
            infrastructure -->
        <!-- Enables the Spring MVC @Controller programming model -->
        <annotation-driven />
        <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
            up static resources in the ${webappRoot}/resources directory -->
        <resources mapping="/resources/**" location="/resources/" />
        <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
            in the /WEB-INF/views directory -->
        <beans:bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <beans:property name="prefix" value="/WEB-INF/views/" />
            <beans:property name="suffix" value=".jsp" />
        </beans:bean>
        <context:component-scan base-package="com.tela.pms" />
        <!-- <beans:bean id="patientService" class="com.tela.pms.service.impl.IndividualPatientServiceImpl"></beans:bean> -->
        <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <beans:property name="url" value="jdbc:mysql://localhost:3306/test" />
            <beans:property name="username" value="root" />
            <beans:property name="password" value="root" />
        </beans:bean>
        <beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <beans:property name="dataSource" ref="dataSource"></beans:property>
            <beans:property name="annotatedClasses">
                <beans:list>
                    <beans:value>com.pms.model.Employee</beans:value>
                </beans:list>
            </beans:property>
            <beans:property name="hibernateProperties">
                <beans:props>
                    <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</beans:prop>
                    <beans:prop key="hibernate.show_sql">true</beans:prop>
                </beans:props>
            </beans:property>
        </beans:bean>
<!-- error is here-->
        <beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory">
        </beans:bean>

    </beans:beans>

帮助将是非常感激的。

在。xml的顶部使用:

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

注意添加的元素:

xmlns:p="http://www.springframework.org/schema/p"

最新更新