Spring PropertyPlaceholderConfigurer从DB加载
是否可以使用Custom Spring PropertyPlaceholderConfigurer从DB加载属性? 提供给自定义PropertyPlaceholderConfigurer的数据源是否也可能在类路径中使用特定的属性文件?
我从以下链接找不到满意的答案?
http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/ http://www.codeproject.com/Articles/28893/Loading-Application-Properties-from-a-Database PropertyPlaceholderConfigurer查找数据库值和使用属性文件作为后备
Spring Context XML
classpath:db.properties
${imosdb.driver} ${imosdb.url} ${imosdb.username} ${imosdb.password} ${imosdb.initial_pool_size} ${imosdb.max_pool_size} ${imosdb.min_pool_size} classpath:static.properties file:static.properties
Java PlaceholderClass
import java.util.Properties; import javax.sql.DataSource; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; public class DbPropertySourcesPlaceholderConfigurer extends PropertyPlaceholderConfigurer { private static final String DEFAULT_DATASOURCENAME = "dataSource"; private static final String DEFAULT_DBTABLENAME = "property"; private static final String DEFAULT_DBKEYCOLUMNNAME = "key"; private static final String DEFAULT_DBVALUECOLUMNNAME = "value"; String dataSourceName; String dbTableName; String dbKeyColumnName; String dbValueColumnName; @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { DataSource dataSource = (DataSource) beanFactory.getBean(getDataSourceName()); // DbProperties dbProps = new DbProperties(dataSource); final Properties dbProps = new Properties(); dbProps.put("app.version", "v3"); setProperties(dbProps); super.postProcessBeanFactory(beanFactory); } public String getDataSourceName() { return dataSourceName==null?DEFAULT_DATASOURCENAME:dataSourceName; } public void setDataSourceName(String dataSourceName) { this.dataSourceName = dataSourceName; } }
特别感谢以下页面的作者。
http://springtips.blogspot.com.tr/
http://ykchee.blogspot.com.tr/2012/09/spring-31-loading-properties-for-xml.html
http://blog.javaforge.net/post/31720600427/configuring-spring-based-web-application-from-database
- 如何使JFormattedTextField接受不带小数点的整数(逗号)?
- Spring Security:取决于实体的不同身份validation方法
- 线程“main”中的exceptionorg.hibernate.MappingException:未知实体
- JavaFX:CheckBoxTableCell在用户检查checkBox时获取ActionEvent
- 使用代理时,ClassLoader无法看到界面?
- NoSuchMethodError:org.slf4j.impl.StaticLoggerBinder.getSingleton()
- JShell不会使用Git Bash执行任何操作
- cucumber(Java中):如何仅使用两个标记运行方案
- 在JSP EL中连接字符串?