spring 设置通过代码启动加载配置文件和设置启动顺序
来源:互联网 发布:淘宝流量如何申请退款 编辑:程序博客网 时间:2024/06/11 09:31
通过这种方式加载可以使用maven模块化,抛开web.xml的束缚。
public class SpringConfigInitializer extends AbstractContextLoaderInitializer
implements WebApplicationInitializer
{
protected WebApplicationContext createRootApplicationContext()
{
String allXml = getRootContextConfigLocation();
XmlWebApplicationContext s = new XmlWebApplicationContext();
s.setConfigLocation(allXml);
return s;
}
public String getRootContextConfigLocation() {
String configLocationParam = "classpath:config/bomf/spring/applicationContext.xml";
Properties props = StrTool.getProperties("/config/bomf/dssp.properties");
boolean webOnly =
Boolean.valueOf(props
.getProperty("webOnly", "false")).booleanValue();
if (!webOnly) {
configLocationParam = configLocationParam + ",classpath:config/bomf/server/*.xml";
}
else {
configLocationParam = configLocationParam + ",classpath:config/bomf/client/*.xml";
}
boolean jaxws = Boolean.valueOf(props.getProperty("jaxws", "false")).booleanValue();
if (jaxws) {
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/jax-ws.xml";
}
boolean hessianConsumer = Boolean.valueOf(props.getProperty("hessianConsumer", "false")).booleanValue();
if (hessianConsumer) {
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/hessian-comsumer.xml";
}
String cacheProvider = props.getProperty("cache.provider", "ehcache");
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/application-cache-" + cacheProvider + ".xml";
boolean dubbo = Boolean.valueOf(props.getProperty("dubbo", "false")).booleanValue();
if (dubbo) {
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/dubbo.xml";
}
if (!webOnly) {
boolean isJndi = Boolean.valueOf(props.getProperty("isJndi", "false")).booleanValue();
if (isJndi) {
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/jndi_db.xml";
}
else {
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/c3p0_db.xml";
}
}
String otherspringxml = props.getProperty("otherspringxml");
if (StrTool.isValid(otherspringxml)) {
configLocationParam = configLocationParam + "," + otherspringxml;
}
String securityType = props.getProperty("securityType", "spring");
if ((StrTool.isValid(securityType)) && (!"none".equals(securityType))) {
configLocationParam = configLocationParam + ",classpath:config/bomf/spring/" + securityType + "-security.xml";
}
return configLocationParam;
}
}
阅读全文
0 0
- spring 设置通过代码启动加载配置文件和设置启动顺序
- spring boot通过jar包启动时,配置文件的加载顺序
- linux设置启动顺序
- Ubuntu下设置启动顺序
- Thinkpad x230设置启动顺序
- Thinkpad E440启动顺序设置
- Ubuntu设置启动项顺序
- centos设置内核启动顺序
- myEclipse启动项加载设置
- 通过修改grub设置Linux和Windows等多个系统的启动顺序变更和删除
- ubuntu9.10和WINDOWS xp双系统启动顺序设置
- Ubuntu9.10以上版本和Windows双系统启动顺序设置
- win 8 和 fedora 19启动顺序设置
- Spring单元测试加载配置文件启动异常
- tomcat启动或,struts2需要加载哪些配置文件,加载顺序
- 通过web.xml文件自动启动spring容器加载对应的配置文件
- 通过JUnit启动spring加载配置
- 设置Linux 服务的开机启动顺序
- BZOJ 1038 [ZJOI 2008] 瞭望塔
- HDU 1217-Arbitrage(Floyd)
- LeetCode-141 Linked List Cycle
- 20个高级Java面试题汇总
- MyBatis使用总结
- spring 设置通过代码启动加载配置文件和设置启动顺序
- opencv 高斯混合模型提取视频或者图片的前景
- redis必杀命令:服务器
- 设计模式の工厂模式
- TCP长连接和短连接的区别
- 六、STL的数值计算---向量(数组)运算--valarray类
- 【树状数组】
- tensorflow训练出现nan的讨论
- GAN原理介绍