如何通过配置spring

如何通过配置spring

本文介绍了如何通过配置spring xml来扩展spring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring 4应用程序中,我们扩展了 PropertySourcesPlaceholderConfigurer 以在解析属性期间执行一些自定义任务.

In a Spring 4 application, we are extending PropertySourcesPlaceholderConfigurer to do some custom task during resolving properties.

要注册我们的新类(MyPropertyConfigurer)o Spring,请使用以下类:

To register our new class (MyPropertyConfigurer) o Spring we use the following class:

@Configuration
public class AppConfig {
  @Bean
    public static PropertySourcesPlaceholderConfigurer
    propertySourcesPlaceholderConfigurer() {
        return new MyPropertyConfigurer();
    }

}

出于好奇,我可以使用spring.xml而不是使用@Configuration注释将新bean添加到Spring吗?

As a matter of curiosity, can I add my new bean to Spring with spring.xml instead of using the @Configuration annotation?

推荐答案

我遇到了同样的问题,只需将类的bean放入我的Springbeans.xml文件中即可解决问题,如下所示:

I had the same problem, my problem was fixed simply with placing the bean of my class in my Springbeans.xml file like below:

<beans:bean class="MyPropertyConfigurer"/>

这篇关于如何通过配置spring xml来扩展spring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 11:50