描述:
- 建立一个基于 SpringMVC 的 Java EE 项目。
- 运行项目,运行良好
- 添加 Hibernate4 框架库支持。
问题,异常
1)在我将'dataSource' bean添加到SpringMVC配置文件后,它总是在启动时抛出。
来自 ServletContext 资源 [/WEB-INF/dispatcher-servlet.xml] 的 XML 文档中的第 45 行无效;嵌套异常是 org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: 匹配通配符是严格的,但找不到元素“tx:annotation-driven”的声明。
2)我提到了匹配的通配符是严格的,但是找不到元素'tx:annotation-driven'的声明
仍然是同样的错误。
SpringMVC 配置 XML 文件
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=test" />
<property name="username" value="root" />
<property name="password" value="123edkx" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<!--HandlerMapping-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!--HandlerAdapter-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<!--ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Views/" />
<property name="suffix" value=".jsp" />
</bean>
<!--Controller -->
<bean class="com.annotation.controllers.Test" />
<bean class="com.annotation.controllers.LogicController" />
问题:
有谁知道如何解决这个问题?或者建议一些关于 SpringMVC3.x 与 Hibernate 4 的集成教程?
<?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: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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://localhost:1443;DatabaseName=beta_nl" />
<property name="username" value="root" />
<property name="password" value="12rekasQL" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--<property name="packagesToScan" value="com.vo" />-->
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations" value="classpath:com/vo/*.hbm.xml"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<!--HandlerMapping-->
<!--<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!--HandlerAdapter-->
<!--<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<!--ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Views/" />
<property name="suffix" value=".jsp" />
</bean>
<!--Controller -->
<bean class="com.annotation.controllers.Test" />
<bean class="com.annotation.controllers.LogicController" />