比如在项目中,我们会把数据库连接信息和redis连接信息放在properties文件中,我想把这个文件里的连接信息变成动态,也不需要去重启服务就可以切换,如何实现?
properties
认证高级PHP讲师
There is a configuration called Profile in Maven, which can be configured differently for different environments.
<profiles> <profile> <id>dev</id> <properties> <db.driver>com.mysql.jdbc.Driver</db.driver> <db.url>jdbc:mysql://192.168.1.100:3306/test</db.url> <db.username>dev</db.username> <db.password>dev-pwd</db.password> </properties> </profile> //可定义多个profile,针对不同环境的不同id <profile> ... <profile> </profiles>
Use the command line to specify different configurations based on different Profile Ids
mvn clean install -P dev
FYI http://stackoverflow.com/questions/14117117/dynamically-loading-properties-file-using-spring
<bean id="myProperties" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <!-- check property file(s) every 1 second --> <property name="cacheSeconds" value="1"/> <property name="basenames"> <list> <value>myApp/myApp</value> </list> </property> </bean>
有一个技术,叫做autoconfig的。你可以百度了解一下。 可以通过配置文件,配置测试环境、开发环境、线上环境,项目会根据不同的情况下,分别加载不同的配置文件。
It is impossible to change the connected database without restarting the server. You can obtain the connection information value, but it is impossible to dynamically switch to another database
Keywordsjrebel
jrebel
There is a configuration called Profile in Maven, which can be configured differently for different environments.
Use the command line to specify different configurations based on different Profile Ids
It is impossible to change the connected database without restarting the server. You can obtain the connection information value, but it is impossible to dynamically switch to another database
Keywords
jrebel