Spring的注入问题

 

spring中可以只用autowire="byName"或者"byType"来提供自动注入。但是大家有一点还需要注意,那就是它不支持基本数据类型(String,int,long等)的自动注入。例

欢迎转载,但请保留出处,本文章转自[华软网] 原文链接:http://www.huarw.com/program/java/java03/200902/1662822.html

 

一个用于spring集成测试的自动注入类

<!-- url:share/Share.js?obj=shareBlogFromCoolPoint--><!-- {"title":"添加博客《一个用于spring集成测...》到我的分享", "queryString":"tid=1&src=404061797&oid=1307241179"} --> <script></script> <script></script>

public abstract class AbstractAotoInjectionBeanTestCase{
    private AutowireCapableBeanFactory beanFactory;
    protected final String[] getConfigLocations() {
        return new String[] { "classpath:applicationContext*.xml" };
    }

    public AbstractAotoInjectionBeanTestCase() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(getConfigLocations());
        beanFactory = context.getAutowireCapableBeanFactory() ;
        beanFactory.autowireBeanProperties(this,AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    }
}

你可能感兴趣的:(spring,html,xml)