首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Spring可否直接注入无接口具体类

2013-12-13 
Spring能否直接注入无接口具体类bean idbService classcom.spring.service.BServiceImpl/beanBS

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();
    }
加上上面配置,是可以测试通过的,能发一些你那边的调用类的相关代码莫

热点排行