2012-07-09 194 views
1

我想委託我的項目在Spring Security中的安全性,但是當我將依賴關係添加到我的POM並啓動服務器時,我得到一個無意義的錯誤......它表示我applicationContext.xml中有一個錯誤,它指向的地方,我有一個AOP句行...AOP彈簧安全錯誤

這裏是我的applicationContext.xml的簡化版本

<?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:util="http://www.springframework.org/schema/util" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:aop="http://www.springframework.org/schema/aop" 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/util http://www.springframework.org/schema/util/spring-util-3.1.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> 

<!-- Activates scanning of @Autowired --> 
    <context:annotation-config/> 

    <!-- Activates scanning of @Repository and @Service --> 
    <context:component-scan base-package="es.myproject"/> 

    <!-- datasource configuration --> 
    <context:property-placeholder location="classpath:jdbc.properties" /> 

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
     <property name="jndiName" value="${jndi.name}" /> 
     <property name="lookupOnStartup" value="true"></property> 
     <property name="cache" value="true"></property> 
     <property name="proxyInterface" value="javax.sql.DataSource"></property> 
    </bean> 

    <!-- hibernate session factory --> 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation" value="classpath:hibernate.cfg.xml" /> 
     <property name="packagesToScan" value="es.myproject.modelo.datos" /> 
    </bean> 

    <!-- enable the configuration of transactional behavior based on annotations --> 
    <aop:aspectj-autoproxy /> 
    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --> 
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

</beans> 

這些是德依賴性:

<!-- Spring security --> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-core</artifactId> 
      <version>3.1.0.RELEASE</version>  

     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>3.1.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>3.1.0.RELEASE</version> 
     </dependency> 

錯誤點<aop:aspectj-autoproxy /> applicationContext.xml中

如果我刪除了Spring安全依賴關係,錯誤消失......怪異的吧?任何人的想法?

錯誤說: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/aop/spring-aop-3.1.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 41 in XML document from ServletContext resource [/WEB-INF/classes/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:aspectj-autoproxy'.

但目前還沒有真正的問題與讀取XSD,正如我說的,如果我刪除了春天的安全依賴這個錯誤不顯示...

回答

3

奇怪。你的XML是有效的(根據W3驗證器),你的bean定義都是合理的。這讓我覺得這是一個類路徑問題。請確保你在你的類路徑以下罐子:

  • aopalliance-1.0.jar
  • 共享記錄-1.0.1.jar
  • 彈簧AOP-3.1.0.RELEASE.jar
  • 彈簧-ASM-3.1.0.RELEASE.jar
  • 彈簧豆-3.1.0.RELEASE.jar
  • 彈簧上下文3.1.0.RELEASE.jar
  • 彈簧核-3.1。 0.RELEASE.jar
  • 彈簧表達-3.1.0.RELEASE.jar
  • 彈簧JDBC-3.1.0.RELEASE.jar
  • 彈簧ORM-3.1.0.RELEASE.jar
  • 彈簧安全芯 - 3.1.0.RELEASE.jar
  • 彈簧安全網絡3.1.0.RELEASE.jar
  • 彈簧TX-3.1.0.RELEASE.jar
  • 彈簧網絡3.1.0.RELEASE。罐子

另外請確保這些都不會出現多次(可能與不同的版本)

啊,重新讀你的問題,問題可能是你沒有明確列出Spring 3.1.x作爲依賴。除非您明確要求,否則Spring Security 3.1.x只會引用Spring 3.0.7。

添加這些依賴關係,你應該是安全的:

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-aop</artifactId> 
    <version>3.1.0.RELEASE</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-orm</artifactId> 
    <version>3.1.0.RELEASE</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-context</artifactId> 
    <version>3.1.0.RELEASE</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-web</artifactId> 
    <version>3.1.0.RELEASE</version> 
</dependency> 
+0

偉大的!我的pom.xml缺少spring-aop,spring-context和spring-web,一旦我更新它,服務器就像一個魅力開始:)謝謝! – diminuta 2012-07-12 10:18:26

+0

您是否嘗試過使用Maven依賴關係(mvn dependency:tree)來檢查您的依賴關係? – gffny 2013-12-21 02:47:43