Problems encountered in Spring reading properties property file configuration items

Three Notes:
Auto Scan
@Component
@Value

package test.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component("myConfig") // This must have
public class myConfig {

    @Value("${userAddress}")
    private String address;

    @Value("${isUse}")
    private String isUser;

    public String getAddress() {
        return address;
    }

    public Boolean isUse() {
        if (isUser == null) {
            return false;
        }
        return Boolean.valueOf(isUser);
    }
}

[test.properties] file content
userAddress=192.168.1.110
isUse = true

<!-- The automatically scanned package name should be added to the package name of the myConfig class-->
    <context:component-scan base-package="demo;test.config"></context:component-scan>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	<property name="locations">
		<list>
			<value>classpath:test.properties</value>
			<value>classpath:test2.properties</value>
		</list>
	</property>
</bean>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326782577&siteId=291194637