Aşağıda yay
bazı yaygın kullanılan yollardır, aynı ulaşmak için çeşitli yollar vardır
- PropertyPlaceholderConfigurer öğesini kullanma
- Pro Kullanma
PropertiesFactoryBean kullanma ResourceBundleMessageSource
kullanma
- ve daha birçok pertySource ........................
ds.type
varsayarsak mülk dosyasında anahtarıdır. PropertyPlaceholderConfigurer
Kayıt kullanma
PropertyPlaceholderConfigurer
fasulyesi
<context:property-placeholder location="classpath:path/filename.properties"/>
veya
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:path/filename.properties" ></property>
</bean>
veya
@Configuration
public class SampleConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
//set locations as well.
}
}
PropertySourcesPlaceholderConfigurer
kaydedilmesi sonra, şimdi value- @PropertySource
ile PropertyPlaceHolderConfigurer
kayıt son bahar sürümünde PropertySource
gerek kullanma
@Value("${ds.type}")private String attr;
, ben iyi buldum erişebilir link sürümün anlaşılabilirliğini anlamak için
Kayıt fasulyesi
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:path/filename.properties</value>
</list>
</property>
</bean>
Erişim Value-
((ApplicationContext)context).getMessage("ds.type", null, null);
veya
0 Kullanılması
@PropertySource("classpath:path/filename.properties")
@Component
public class BeanTester {
@Autowired Environment environment;
public void execute(){
String attr = this.environment.getProperty("ds.type");
}
}
PropertiesFactoryBean
Kayıt fasulyesi kullanarak
@Component
public class BeanTester {
@Autowired MessageSource messageSource;
public void execute(){
String attr = this.messageSource.getMessage("ds.type", null, null);
}
}
<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:path/filename.properties</value>
</list>
</property>
</bean>
Tel Özellikleri örneği size class-içine
@Component
public class BeanTester {
@Autowired Properties properties;
public void execute(){
String attr = properties.getProperty("ds.type");
}
}
Bu [özelliklerine] gibi görünmüyor (http : //en.wikipedia.org/wiki/.propertie s) dosyası. – Raghuram
Eğer Java anlamda bir özellik dosyası ise - evet. Aksi takdirde, farklı bir şekilde ele alınması gereken özel bir dosya formatıdır (ve eğer bir anahtar yoksa, yayında yalnızca özellik değerleri olarak satırları kullanamazsınız). –
"Geleneksel olarak değil" - Bununla ne demek istiyorsun? –