spring注解注入properties配置文件

阅读: 评论:0

2024年1月26日发(作者:)

spring注解注入properties配置文件

1 /** 2 * Abstract base class for property resource configurers that resolve placeholders 3 * in bean definition property values. Implementations pull values from a 4 * properties file or other {@linkplain tySource 5 * property source} into bean definitions. 6 * 7 *

The default placeholder syntax follows the Ant / Log4J / JSP EL style: 8 * 9 *

${...}
10 *11 * Example XML bean definition:12 *13 *
14  * 15  *   16  *   17  * 18  * 
19 *20 * Example properties file:21 *22 *
driver=23  * dbname=mysql:mydb
24 *25 * Annotated bean definitions may take advantage of property replacement using26 * the {@link @Value} annotation:27 *28 *
@Value("${}")
29 *30 * Implementations check simple property values, lists, maps, props, and bean names31 * in bean references. Furthermore, placeholder values can also cross-reference32 * other placeholders, like:33 *34 *
rootPath=myrootdir35  * subPath=${rootPath}/subdir
36 *37 * In contrast to {@link PropertyOverrideConfigurer}, subclasses of this type allow38 * filling in of explicit placeholders in bean definitions.39 *40 *

If a configurer cannot resolve a placeholder, a {@link BeanDefinitionStoreException}41 * will be thrown. If you want to check against multiple properties files, specify multiple42 * resources via the {@link #setLocations locations} property. You can also define multiple43 * configurers, each with its own placeholder syntax. Use {@link44 * #ignoreUnresolvablePlaceholders} to intentionally suppress throwing an exception if a45 * placeholder cannot be resolved.46 *47 *

Default property values can be defined globally for each configurer instance48 * via the {@link #setProperties properties} property, or on a property-by-property basis49 * using the default value separator which is {@code ":"} by default and50 * customizable via {@link #setValueSeparator(String)}.51 *52 *

Example XML property with default value:53 *54 *

55  *   56  * 
57 *58 * @author Chris Beams59 * @author Juergen Hoeller60 * @since 3.161 * @see PropertyPlaceholderConfigurer62 * @see tySourcesPlaceholderConfigurer63 */64 public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfigurer65 implements BeanNameAware, BeanFactoryAware {66

67 /** Default placeholder prefix: {@value} */68 public static final String DEFAULT_PLACEHOLDER_PREFIX = "${";69

70 /** Default placeholder suffix: {@value} */71 public static final String DEFAULT_PLACEHOLDER_SUFFIX = "}";72

73 /** Default value separator: {@value} */74 public static final String DEFAULT_VALUE_SEPARATOR = ":";75

76

77 /** Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX} */78 protected String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;79

80 /** Defaults to {@value #DEFAULT_PLACEHOLDER_SUFFIX} */81 protected String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX;82

83 /** Defaults to {@value #DEFAULT_VALUE_SEPARATOR} */84 @Nullable

spring注解注入properties配置文件

本文发布于:2024-01-26 03:46:29,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/1706211989681.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:配置文件   注解   注入
留言与评论(共有 0 条评论)
   
验证码:
排行榜

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23