日期:2014-05-18  浏览次数:20745 次

Spring能否直接注入无接口具体类
<bean id="bService" class="com.spring.service.BServiceImpl"></bean>
BServiceImpl 没有接口,直接在spring中配置获取的是null,求高手

------解决方案--------------------
三种注入方式 设值注入,接口注入,构造方法注入。 你的是那种?
------解决方案--------------------
可以直接注入的。

问题是,你注入的地方是怎么声明属性和配置的。

另外声明周期,applicationContext的作用域也要考虑清楚。
------解决方案--------------------
新增配置:
<bean id="aopTest" class="com.spring.aop.AOPTest" >
     <property name="aService" ref="aService"/>
     <property name="bService" ref="bService"/>
</bean>
测试调用:
   @Test
   public void testSpring(){             
                ClassPathXmlApplicationContext context = new                            
                                ClassPathXmlApplicationContext("config/applicationContext.xml");
AOPTest test = (AOPTest)context.getBean("aopTest");
test.testCall();
    }
加上上面配置,是可以测试通过的,能发一些你那边的调用类的相关代码莫