2012-12-14 99 views
2

我是這個小世界的新成員,我正在嘗試開發Spring Ldap事務,並且在創建Spring bean時遇到嚴重問題。Spring LDAP事務

我有這個配置XML文件:

<bean id="ldapContextSource" class="org.springframework.ldap.core.support.LdapContextSource"> 
    <property name="url" value="ldap://localhost:10389" /> 
    <property name="base" value="dc=***,dc=com" /> 
    <property name="authenticationSource" ref="authenticationSource" /> 
    <property name="pooled" value="false" /> 
    <property name="baseEnvironmentProperties"> 
     <map> 
      <entry key="com.sun.jndi.ldap.connect.timeout" value="500" /> 
      <entry key="java.naming.referral" value="follow" /> 
     </map> 
    </property> 
</bean> 

<bean id="authenticationSource" 
    class="org.springframework.ldap.authentication.DefaultValuesAuthenticationSourceDecorator"> 
    <property name="target" ref="springSecurityAuthenticationSource" /> 
    <property name="defaultUser" value="uid=admin,ou=system" /> 
    <property name="defaultPassword" value="secret" /> 
</bean> 

<bean id="springSecurityAuthenticationSource" 
    class="org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource" /> 

<bean id="ldapTransactionContextSource" 
    class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy"> 
    <constructor-arg ref="ldapContextSource" /> 
</bean> 

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"> 
    <constructor-arg ref="ldapTransactionContextSource" /> 
</bean> 

<bean id="transactionManager" 
    class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager"> 
    <property name="contextSource" ref="ldapTransactionContextSource" /> 
</bean> 

<bean id="userDaoTarget" class="com.***.daos.UserDao"> 
    <property name="ldapTemplate" ref="ldapTemplate" /> 
</bean> 

<bean id="userDao" 
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
    <property name="transactionManager" ref="transactionManager" /> 
    <property name="target" ref="userDaoTarget" /> 
    <property name="transactionAttributes"> 
     <props> 
      <prop key="*">PROPAGATION_REQUIRES_NEW</prop> 
     </props> 
    </property> 
</bean> 

而且我有問題,當創建 「userDaoTarget」 豆,因爲它trows此異常:

java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472) 
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140) 
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84) 

Finaly我UserDao.class是下一個代碼:

public class UserDao extends CommonDao implements ICommonDao<User> { 

    private LdapTemplate ldapTemplate; 

    public void setLdapTemplate(LdapTemplate ldapTemplate) { 
     this.ldapTemplate = ldapTemplate; 
    } 
} 

有人可以幫我創建bean嗎?我認爲代碼是正確的,但我不知道會發生什麼......

感謝所有爲您的時間

+0

你missig'org.springframework.beans.FatalBeanException'類在你的lib – kromit

回答

0

什麼Spring的依賴你有你的類路徑?具體而言,您是否有

org.springframework.beans-<version>.jar 

神器?

+0

對不起,我的回答延遲,但我是從我的國家。我在pom.xml中有依賴關係 – scastiello

0

這是依賴關係。

<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-ldap</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.ldap</groupId> 
     <artifactId>spring-ldap-core</artifactId> 
     <version>1.3.1.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-pool</groupId> 
     <artifactId>commons-pool</artifactId> 
     <version>1.5.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.directory.server</groupId> 
     <artifactId>apacheds-all</artifactId> 
     <version>1.5.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.5.6</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-beans</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-logging</groupId> 
     <artifactId>commons-logging</artifactId> 
     <version>1.0.4</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <version>3.1.3.RELEASE</version> 
    </dependency>