下面列出了org.springframework.context.support.PropertySourcesPlaceholderConfigurer#setIgnoreUnresolvablePlaceholders ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
AbstractApplicationContext createApplicationContext(Domain domain) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setParent(gatewayApplicationContext);
context.setClassLoader(new ReactorHandlerClassLoader(gatewayApplicationContext.getClassLoader()));
context.setEnvironment((ConfigurableEnvironment) gatewayApplicationContext.getEnvironment());
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreUnresolvablePlaceholders(true);
configurer.setEnvironment(gatewayApplicationContext.getEnvironment());
context.addBeanFactoryPostProcessor(configurer);
context.getBeanFactory().registerSingleton("domain", domain);
context.register(HandlerConfiguration.class);
context.setId("context-domain-" + domain.getId());
context.refresh();
return context;
}
/**
* propertySourcesPlaceholderConfigurer .
* @return propertySourcesPlaceholderConfigurer
* @throws IOException null
*/
@Bean (name = "propertySourcesPlaceholderConfigurer")
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer()
throws IOException {
ClassPathResource classPathResource1 =
new ClassPathResource(ConstantsProperties.classPathResource(
ConstantsProperties.applicationPropertySource));
ClassPathResource classPathResource2 =
new ClassPathResource(ConstantsProperties.classPathResource(
ConstantsProperties.maxKeyPropertySource));
PropertySourcesPlaceholderConfigurer configurer =
new PropertySourcesPlaceholderConfigurer();
configurer.setLocations(
classPathResource1,
classPathResource2
);
configurer.setIgnoreUnresolvablePlaceholders(true);
_logger.debug("PropertySourcesPlaceholderConfigurer init");
return configurer;
}
AbstractApplicationContext createApplicationContext(Api api) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setParent(gatewayApplicationContext);
context.setClassLoader(new ReactorHandlerClassLoader(gatewayApplicationContext.getClassLoader()));
context.setEnvironment((ConfigurableEnvironment) gatewayApplicationContext.getEnvironment());
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreUnresolvablePlaceholders(true);
configurer.setEnvironment(gatewayApplicationContext.getEnvironment());
context.addBeanFactoryPostProcessor(configurer);
context.getBeanFactory().registerSingleton("api", api);
context.register(ApiHandlerConfiguration.class);
context.setId("context-api-" + api.getId());
context.refresh();
return context;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
MutablePropertySources propertySources = new MutablePropertySources();
MockPropertySource source = new MockPropertySource()
.withProperty("rabbitmq.host", "192.168.10.10")
.withProperty("rabbitmq.port", "5673")
.withProperty("rabbitmq.username", "jfw")
.withProperty("rabbitmq.password", "jfw")
.withProperty("rabbitmq.channel-cache-size", 100);
propertySources.addLast(source);
configurer.setPropertySources(propertySources);
return configurer;
}
/**
* Register {@link PropertySourcesPlaceholderConfigurer} Bean
*
* @param registry {@link BeanDefinitionRegistry}
* @param beanFactory {@link BeanFactory}
*/
public static void registerPropertySourcesPlaceholderConfigurer(
BeanDefinitionRegistry registry, BeanFactory beanFactory) {
registerInfrastructureBeanIfAbsent(registry, PLACEHOLDER_CONFIGURER_BEAN_NAME,
PropertySourcesPlaceholderConfigurer.class);
/*
* If you can't guarantee your old project properties file and config items are
* complete , please setIgnoreUnresolvablePlaceholders setIgnoreResourceNotFound
* is true 。 if not,you may not be able to start the spring container and your
* application
*/
boolean ignoreResourceNotFound = Boolean
.parseBoolean(System.getProperty(IGNORE_RESOURCE_NOT_FOUND));
boolean ignoreUnresolvablePlaceholders = Boolean
.parseBoolean(System.getProperty(IGNORE_UNRESOLVABLE_PLACEHOLDERS));
if (ignoreResourceNotFound || ignoreUnresolvablePlaceholders) {
PropertySourcesPlaceholderConfigurer configurer = (PropertySourcesPlaceholderConfigurer) beanFactory
.getBean(NacosBeanUtils.PLACEHOLDER_CONFIGURER_BEAN_NAME);
if (configurer != null) {
configurer.setIgnoreResourceNotFound(ignoreResourceNotFound);
configurer.setIgnoreUnresolvablePlaceholders(
ignoreUnresolvablePlaceholders);
}
}
}
@Override
public ProtocolProvider create(String type, ApplicationContext parentContext) {
logger.debug("Looking for an protocol provider for [{}]", type);
Protocol protocol = protocols.get(type);
if (protocol != null) {
try {
ProtocolProvider protocolProvider = createInstance(protocol.protocolProvider());
Plugin plugin = protocolPlugins.get(protocol);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.setParent(parentContext);
context.setClassLoader(pluginClassLoaderFactory.getOrCreateClassLoader(plugin));
context.setEnvironment((ConfigurableEnvironment) parentContext.getEnvironment());
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreUnresolvablePlaceholders(true);
configurer.setEnvironment(parentContext.getEnvironment());
context.addBeanFactoryPostProcessor(configurer);
context.register(protocol.configuration());
context.registerBeanDefinition(plugin.clazz(), BeanDefinitionBuilder.rootBeanDefinition(plugin.clazz()).getBeanDefinition());
context.refresh();
context.getAutowireCapableBeanFactory().autowireBean(protocolProvider);
if (protocolProvider instanceof InitializingBean) {
((InitializingBean) protocolProvider).afterPropertiesSet();
}
return protocolProvider;
} catch (Exception ex) {
logger.error("An unexpected error occurs while loading protocol", ex);
return null;
}
} else {
logger.error("No protocol provider is registered for type {}", type);
throw new IllegalStateException("No protocol provider is registered for type " + type);
}
}
@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[]{ new ClassPathResource("foo.properties") };
pspc.setLocations(resources);
pspc.setIgnoreUnresolvablePlaceholders(true);
return pspc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new Resource[] {new ClassPathResource("/conf/molgenis.properties")};
pspc.setLocations(resources);
pspc.setFileEncoding("UTF-8");
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setIgnoreResourceNotFound(true);
pspc.setNullValue("@null");
return pspc;
}
protected static PropertySourcesPlaceholderConfigurer createPropertySourcesPlaceholderConfigurer(Resource... resources) {
final PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.setIgnoreResourceNotFound(false);
ppc.setLocations(resources);
return ppc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
c.setLocation(new ClassPathResource("git.properties"));
c.setIgnoreResourceNotFound(true);
c.setIgnoreUnresolvablePlaceholders(true);
return c;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
pspc.setIgnoreResourceNotFound(true);
pspc.setIgnoreUnresolvablePlaceholders(true);
return pspc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
pspc.setIgnoreResourceNotFound(true);
pspc.setIgnoreUnresolvablePlaceholders(true);
return pspc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
return configurer;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
return configurer;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
MutablePropertySources propertySources = new MutablePropertySources();
MockPropertySource source = new MockPropertySource()
.withProperty("rabbitmq.port", "invalid");
propertySources.addLast(source);
configurer.setPropertySources(propertySources);
return configurer;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
return configurer;
}
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new Resource[] {new ClassPathResource("/conf/molgenis.properties")};
pspc.setLocations(resources);
pspc.setFileEncoding("UTF-8");
pspc.setIgnoreUnresolvablePlaceholders(true);
pspc.setIgnoreResourceNotFound(true);
pspc.setNullValue("@null");
return pspc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigurer() {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
pspc.setIgnoreUnresolvablePlaceholders(true);
return pspc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
final PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
final PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
}