Announcement Announcement Module
Collapse
No announcement yet.
@Inject from properties file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Inject from properties file

    In xml, we can use value="${...}".
    But when I use @Inject, how can I inject the value from properties file?

    Thanks.

  • #2
    Create config.properties in your classpath like this:
    Code:
    url=http://www...
    Add to spring config XML:
    Code:
    <context:spring-configured />
    <context:annotation-config />
    <util:properties id="config" location="classpath:config.properties" />
    and then in your class:
    Code:
    @Service
    public class SomeService {
    
    	@Value(value = "#{config['url']}")
    	private String url;

    Comment


    • #3
      Thanks for your information.

      If I already have the following configuration, can I reuse the propertyConfigurer bean?

      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"
      p:location="classpath:aaa.properties" />

      Comment

      Working...
      X