2013-07-10 78 views
4

如果我不粘貼xmlns:tx="http://www.springframework.org/schema/tx"那麼就沒有問題。但是,如果我插入文本,我會得到一個cvc-complex-type.2.4.c:匹配通配符是嚴格的,但是對於元素'tx:annotation-driven'錯誤沒有聲明。cvc-complex-type.2.4.c:匹配通配符是嚴格的,但是對於元素'tx:annotation-driven'沒有聲明。

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

    <context:annotation-config /> 
    <tx:annotation-driven /> 
<context:component-scan base-package="ne.projl.server" /> 

    <bean name="security.securityInfo" class="org.geomajas.security.SecurityInfo"> 
     <property name="loopAllServices" value="false" /> 
     <property name="securityServices"> 
      <list> 
       <bean class="org.geomajas.security.allowall.AllowAllSecurityService" /> 
      </list> 
     </property> 
    </bean> 

    <bean name="puregwt-app" class="org.geomajas.configuration.client.ClientApplicationInfo"> 
     <property name="maps"> 
      <list> 
       <ref bean="mapOsm" /> 
<!--    <ref bean="mapWms" /> --> 
<!--    <ref bean="mapLegend" /> --> 
<!--    <ref bean="mapLayerVisibility" /> --> 
<!--    <ref bean="mapCountries" /> --> 
<!--    <ref bean="mapEmpty" /> --> 
<!--    <ref bean="mapPrinting" /> --> 
      </list> 
     </property> 
    </bean> 
<bean class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" id="entityManagerFactory"> 
     <property name="persistenceUnitName" value="MyPUnit" /> 
    </bean> 

    <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> 
     <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    </bean> 
</beans> 

我還試圖修改<tx:annotation-driven />像這樣:<tx:annotation-driven transaction-manager="transactionManager"/>

回答

9

爲TX模式位置是從來沒有在<beans>標籤提供。注意提供的配置的最後一行中的更改。此外,配置將Spring 2.0與2.5混合,我不確定這是否是需要的,但我想讓你知道這一點。

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

即使這是前一段時間,這對我很有幫助。謝謝 – Cyrex

0

這是爲我工作與Spring 3.X +休眠+ MySQL的+ Maven的

的servlet-context.xml的

<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 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" 
    xmlns:tx="http://www.springframework.org/schema/tx"> 

    <!-- 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:annotation-config /> 



    <beans:bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <beans:property name="dataSource" ref="dataSource" /> 
     <beans:property name="hibernateProperties"> 
      <beans:props> 
       <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect 
       </beans:prop> 
       <beans:prop key="hibernate.show_sql">true</beans:prop> 
      </beans:props> 
     </beans:property> 
     <beans:property name="packagesToScan" value="com.hb.test.modal" /> 
    </beans:bean> 


    <beans:bean id="dataSource" name="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <beans:property name="url" 
      value="jdbc:mysql://localhost:3306/mydb" /> 
     <beans:property name="username" value="root" /> 
     <beans:property name="password" value="root" /> 
    </beans:bean> 
    <beans:bean id="transactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <beans:property name="sessionFactory" ref="sessionFactory" /> 
    </beans:bean> 
    <tx:annotation-driven transaction-manager="transactionManager" /> 
    <context:component-scan base-package="com.hb.test" /> 

</beans:beans> 

的pom.xml

<!--Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>3.6.0.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.persistence</groupId> 
     <artifactId>persistence-api</artifactId> 
     <version>1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>3.0.5.RELEASE</version> 
    </dependency> 


    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-jdbc</artifactId> 
     <version>4.0.0.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.32</version> 
    </dependency> 
    <!-- AOP dependency --> 
    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2</version> 
    </dependency> 

    <dependency> 
     <groupId>javassist</groupId> 
     <artifactId>javassist</artifactId> 
     <version>3.12.1.GA</version> 
    </dependency> 
1

我需要換行的內容刪除error--

http://www.springframework.org/schema/context/spring-context-4.0.xsd 
http://www.springframework.org/schema/context 

只是一個交換解決了我的錯誤 - 如下

http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd 
0

當我們處理xml文件中的錯誤時,應該注意到,eclipse有bug,如果我們c出錯的線路,然後再次粘貼回來,這些錯誤可能會作爲一種魔法消失。我已經多次碰到這個eclipse bug。

相關問題