说明
问题,异常
1)在我将'dataSource'bean添加到SpringMVC配置文件后,它会在启动时抛出。
来自ServletContext资源[/WEB-INF/dispatcher-servlet.xml]的XML文档中的第45行无效;嵌套异常是org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:匹配的通配符是strict,但是找不到元素'tx:annotation-driven'的声明。
2)我提到The matching wildcard is strict, but no declaration can be found for element '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" />
答案 0 :(得分:0)
我认为你没有将xsd添加到配置文件的开头。 下面是您将使用的xsd和定义。 的xmlns:TX = “http://www.springframework.org/schema/tx” http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd“。如果你想使用tx注释,你还应该配置一个事务管理器。
答案 1 :(得分:0)
我最近使用过http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/,其配置正常。
请发布完整配置,命名空间deсlarations等。
更新:请检查是否存在xsi名称空间声明
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"