java - 将bean xml转换为spring boot注解
问题描述
我有以下来自 spring 框架的 bean xml。现在我们正在转向带有所有注释的 Spring Boot。如何将以下 bean 转换为注释?
<bean id="testPool" class="com.v1.testPoolImpl" init-method="init" destroy-method="shutdown">
<property name="configurations">
<bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:database.properties"/>
</bean>
</property>
</bean>
com.v1.testPoolImpl (是其他一些库)
解决方案
您可以创建新Configuration
课程。<bean>
您可以使用注释重写@Bean
,然后创建new
类的实例并使用设置变量的设置器。
@Configuration
public class Config {
@Bean(initMethod = "init" , destroyMethod = "shutdown")
public Object testPool(){
testPoolImpl testPool = new testPoolImpl();
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation( new ClassPathResource("database.properties"));
propertiesFactoryBean.afterPropertiesSet();
testPool.setConfigurations(propertiesFactoryBean.getObject());
return testPool;
}
}
推荐阅读
- ios - 为 pjsip 构建时,在 libssl.a 中找不到架构 x86_64 的符号
- android - 具有自定义 GATT 服务的网络蓝牙?
- c# - 脚手架创建视图返回 System.Web.Mvc.WebViewPage
.Model.get 返回空值。发帖前 - java - 将 ArrayList 转换为 JSON 文件
- c# - 我怎样才能得到一个排序的`列表
` 基于关联的数字索引 - ios - 根据选择自动向下滚动
- php - 如何从 Laravel 集合中获取最小日期
- node.js - Id 没有从嵌套数组中删除
- gremlin - 无法使用图形管理实例
- javascript - 引导弹出窗口内元素的 document.querySelector