Weblogic 10.3.6 Spring 3.2@Autowired不';行不通

Weblogic 10.3.6 Spring 3.2@Autowired不';行不通,spring,weblogic,Spring,Weblogic,无法使自动布线工作。目前,我们的组织无法升级到Weblogic。以下是启动网站时浏览器显示的内容。此外,还包括相关编码,如图所示 org.springframework.beans.factory.BeanCreationException:创建名为“acmeService”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动关联字段:private com.acme.dat

无法使自动布线工作。目前,我们的组织无法升级到Weblogic。以下是启动网站时浏览器显示的内容。此外,还包括相关编码,如图所示

org.springframework.beans.factory.BeanCreationException:创建名为“acmeService”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动关联字段:private com.acme.data.AcmeDao com.acme.service.AcmeService.AcmeDao;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:未找到依赖项类型为[com.acme.data.AcmeDao]的符合条件的bean:应至少有1个bean符合此依赖项的autowire候选项的条件。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

context.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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:annotation-config/>

    <bean id="baseDao" class="com.acme.BaseDao" abstract="true">
        <property name="dataSource" ref="oracleDS" />
    </bean>

    <bean id="oracleDS" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc-acme" />
    </bean>

    <bean id="service" class="com.acme.service.AcmeService">
        <property name="acmeDao" ref="acmeDao" />
    </bean>

    <bean id="acmeDao" class="com.acme.service.AcmeDao"
        parent="baseDao" /> 

</beans>

仔细查看完整的堆栈跟踪。Spring堆栈跟踪非常冗长,如果您不注意,可能很难解释。特别是,当根本原因是无法创建要注入的bean时,您可能会得到一个异常,说明注入失败


这将在堆栈跟踪中指定,但稍微向下一点。例如,在这种情况下,一个可能的原因可能是无法创建数据源,例如,如果JNDI名称不正确。

AcmeService.class中存在两个问题

1) 您已导入com.acme.data.AcmeDao,但您正在context.xml中引用com.acme.service.AcmeDao

2) 您正在context.xml中的acmeservicebean定义中设置com.acme.service.AcmeDao引用


如果要引用com.acme.service.AcmeDao,请将导入更改为com.acme.service.AcmeDao。然后,删除@Autowired注释,因为您已经在context.xml中引用了它。

通过在AcmeDao中添加@Repository使其工作。不知道为什么会这样。

谢谢你的建议,但需要自动连线。通过在AcmeDao中添加@Repository使其正常工作。不知道为什么。另外,在AcmeService中临时添加了构造函数来调试并确保类已实例化。我看到其他帖子建议使用@westcoastmilt,因为acmeDao是在xml配置和注释中指定的,我说注释不是必需的,因为xml配置将优先。
package com.acme.service;

import com.acme.data.AcmeDao;
import com.acme.load.beans.ProviderEligibilityBean;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AcmeService implements AcmeServiceInterface {

    final Logger logger = Logger.getLogger(AcmeService.class);

    @Autowired
    private AcmeDao acmeDao;
    public void setAcmeDao(AcmeDao acmeDao) {
        this.acmeDao = acmeDao;
    }
...