Spring is set in properties file by @value, and differs from @value # and $

Source: Internet
Author: User

Spring gets the value method of properties

Configuring in Spring.xml

Oddly enough, the Context-param loaded spring.xml cannot use ${xxx}

Must be handed over to Dispatcherservlet management springmvc.xml to use?

To give Springmvc dispatcherservlet to scan, instead of Spring listener Contextloaderlistener to scan, it can be more convenient to use "${xxx" to inject.

1. Use $ to get properties

@Value ("${user.name}")

Private String UserName;

<!--方法1-->
<location= "Classpath*:info/info.properties"/>
<!--方法2-->
<Beanclass= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">    < Propertyname= "Order"value= "1" />    < Propertyname= "Locations">        <List>            <value>Classpath:info/info.properties</value>        </List>    </ Property></Bean>

2. Use #获取属性

@Value ("#{user.name}")

Private String UserName;

<BeanID= "prop"class= "Org.springframework.beans.factory.config.PropertiesFactoryBean">         < Propertyname= "Locations">             <Array>                 <value>Classpath:configure.properties</value>             </Array>         </ Property> </Bean>

Spring is set in properties file by @value, and differs from @value # and $

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.