我是新來的春天,在我的項目中,我使用屬性文件來讀取像這樣的IP配置。春季外部配置
@Configuration
@PropertySource("classpath:ipaddress.properties")
在我的屬性文件
ip=http://192.168.1.199:8888
屬性文件在我的項目存在(com.test ....),但我想從我的項目中刪除和讀取的IP地址從jboss配置或別的什麼地方。如果有人能指導我這一點,將不勝感激。提前致謝。
我是新來的春天,在我的項目中,我使用屬性文件來讀取像這樣的IP配置。春季外部配置
@Configuration
@PropertySource("classpath:ipaddress.properties")
在我的屬性文件
ip=http://192.168.1.199:8888
屬性文件在我的項目存在(com.test ....),但我想從我的項目中刪除和讀取的IP地址從jboss配置或別的什麼地方。如果有人能指導我這一點,將不勝感激。提前致謝。
您使用的是maven嗎?如果是的話,這也許這將是將此放入Maven的輪廓好主意,這樣的:
的pom.xml
...
<profiles>
<profile>
<id>dev</id>
<properties>
<ip.address>http://192.168.1.199:8888</ip.address>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<ip.address>http://10.34.65.1:8888</ip.address>
</properties>
</profile>
<profiles>
...
<properties>
<resource.directory>src/main/resources</resource.directory>
</properties>
...
<build>
<resources>
<resource>
<directory>${resource.directory}</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
...
ipaddress.properties:
ip=${ip.address}
Maven會然後把IP活躍配置文件的地址,同時建立到ipaddress.properties中 - 這樣您就可以在不更改代碼或屬性的情況下更改ips - 只需設置活動配置文件即可。
,你可以嘗試使用類似的東西:
@PropertySources({
@PropertySource("classpath:application.properties"),
@PropertySource(value = "file:config/application.properties", ignoreResourceNotFound = true)
})
file:config/application.properties
應該是外部application.properties文件的位置。
如果你使用的是Spring Boot,那麼這個Externalized Configuration可能會讓你知道如何去做。
就我而言,我的項目部署在Centos 7服務器上。我這樣做了:
java -jar <spring-application>.jar --spring.config.location=file:/path-to-property-file/application.properties
非常感謝您的幫助。我終於得到了我的獨立使用JNDI的答案是如下:
<subsystem xmlns="urn:jboss:domain:naming:1.2">
<bindings>
<simple name="java:/ip" value=" http://123.456.789.123:4567"/>
</bindings>
</subsystem>
我在代碼中刪除此
@PropertySource("classpath:ipaddress.properties")