hibernate 自动连接依赖注入失败,org.springframework.beans.factory.BeanCreationException

xghobddn  于 2023-10-23  发布在  Spring
关注(0)|答案(1)|浏览(126)

我把spring库升级到了3.2.9,以进行java 8升级。我得到以下错误。任何指针将不胜感激

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'acsManagerImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.taxstream.acs.repository.LdapDAO net.taxstream.acs.service.AcsManagerImpl.ldapDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapDao' defined in ServletContext resource [/WEB-INF/caa-servlet.xml]: Cannot resolve reference to bean 'ldapTemplate' while setting bean property 'ldapTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapTemplate' defined in ServletContext resource [/WEB-INF/caa-servlet.xml]: Cannot resolve reference to bean 'contextSource' while setting bean property 'contextSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'contextSource' is defined

这是AcsManagerImpl:

@Service
public class AcsManagerImpl implements AcsManager {

    @Autowired
    private AcsRepository acsRepository;
    
    @Autowired
    private LdapDAO ldapDao;

    /**
     * @param acsRepository the acsRepository to set
     */
    public void setAcsRepository(AcsRepository acsRepository) {
        this.acsRepository = acsRepository;
    }

    public <T extends Serializable> Page<T> getComponent(Class<T> type, Pageable pageable) {
        return acsRepository.getComponent(type, pageable);
    }

}

这就是LDAPDAO:

public interface LdapDAO<E> {

    List<E> getUserInfo(final String uid);

    List<E> searchUsers(final String uid);

    void setFilter(final String filter);

    void setAttributes(final String[] attrs);
}

这是CAAservlet代码片段

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate" 
       p:contextSource-ref="contextSource" 
       p:ignorePartialResultException="true" 
    />
    
    <bean id="ldapDao" class="net.acs.repository.LdapDaoImpl"> 
       <property name="ldapTemplate" ref="ldapTemplate" /> 
       <property name="filter" value="(uid=@)" />
       <property name="attributes">
           <list>
               <value>cn</value>
               <value>mail</value>
               <value>uid</value>
               <value>givenname</value>
               <value>sn</value>
           </list>
       </property> 
   </bean>

上下文源在application context.xml中定义:

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
       
       <property name="url" value="ldap://C5QSQ13:10389/" />
       <property name="base" value="ou=people,o=sevenSeas" />
        <property name="anonymousReadOnly" value="true" />
    </bean>
sauutmhj

sauutmhj1#

看起来你缺少一个contextSource。它在完整的错误信息中。

No bean named 'contextSource' is defined

示例:

<ldap:context-source
    username="cn=Administrator"
    password="secret"
    url="ldap://localhost:389" />

更多信息-> https://docs.spring.io/spring-ldap/docs/current/reference/#code-contextsource-code-configuration

相关问题