Questions about configuring multiple propertyConfigurers of the Spring framework

https://blog.csdn.net/aa427/article/details/38375259


Recently, I am more interested in caching in the web architecture, so I tried to configure redis and memcache in the windows environment. I just started with Memcache, and there is no problem in running the project (the project framework is SpringMvc+MyBatis). My Spring The configuration file directory is as follows

Start and load applicationContext.xml from the web project, which was originally a relatively simple configuration (there was no problem before configuring memcache and redis). Later, in order to configure memcache, I started again in web.xml, web. The xml configuration adds another xml, as shown below

propertyConfigure is configured again in Spring-memcache.xml

Start the project, there is no problem at present, but when I configure redis next, I also configure it according to this idea, so I added spring-redis.xml to web.xml  

And another propertyConfigure is configured in spring-redis.xml

When I started the project, I thought that there should be no problem with such a configuration, but I didn't expect an error, and something went wrong

It is said that it cannot be replaced. After thinking about it, this is not right. Obviously, the properties in the properties file are the same. It is impossible to go wrong. Finally found the resource

http://www.iteye.com/topic/1131688

http://blog.sina.com.cn/s/blog_4550f3ca0100ubmt.html


Looking up the information, it turned out that spring-memcache.xml was loaded first and then

但是spring是要把3个xml都加载完的 所以上面的memcache.propertis里面的配置在还没有读取出来的时候,spring容器开始要替换里面的表达式,所以出现这么个问题(简单来说就是最好把properties文件全部在一个propertiesConfigure加载)


现在来说解决方案

1)在applicationcontext.xml中进行配置文件的集合,

在各个分配置中,不再配置propertyConfigure了,这样就解决了这么个问题


2)如果觉得还是想非要分别配置更好理解的话

那么在各个propertyConfigure加上“orderr”和“ignoreUnresolvablePlaceholders”,order表示顺序,值越小优先级越高即越早执行;

默认情况下ignore-unresolvable;即如果没找到的情况是否抛出异常。默认false:即抛出异常;

这么配置的意思是先加载memcache.properties文件,在替换表达式的时候不会报错,等待以后的表达式替换(因为配置了ignoreUnresolvablePlaceh=true),则等待加载了redis.propertie文件的时候把其余的表达式给替换掉

(这样配置的要求在于order最大的的ignoreUnresolvablePlace为false,其余的都必须为true,因为先加载的在替换的时候不能报错,等待后面把表达式替换掉)



第二个问题:

这解决了上次配置框架的时候出现的问题,终于无意中找到了答案,在此记录下


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326040592&siteId=291194637