如何将org.springframework中的XML bean转换为注释

时间:2016-04-29 06:29:16

标签: java xml spring

我想将xml bean创建转换为注释。我已经转换了一些,但我对这个有问题:

<bean id="anyClass" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="target">
        <bean class="pl.spring.demo.class.impl.AnyClassImpl">
            <property name="anyName" ref="anyName" />
        </bean>
    </property>
    <property name="interceptorNames">
        <list>
            <value>anyValue</value>
        </list>
    </property>
</bean>

1 个答案:

答案 0 :(得分:2)

如果您想尝试使用Spring Java Beans,可以试试这样:

@Configuration
public class ProxyFactoryBeanConfiguration{

    @Autowired
    private pl.spring.demo.class.impl.AnyClassImpl anyClassImpl;

    @Autowired
    private List<String> interceptorNames;

    @Bean
    public org.springframework.aop.framework.ProxyFactoryBean anyClass(){
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        proxyFactoryBean.setTarget(anyClassImpl);
        proxyFactoryBean.setInterceptorNames(interceptorNames);
        return proxyFactoryBean;
    }

}

确保使用所需的依赖项注入anyClassImpl。