spring讀取propertyes 新方法

<context:property-placeholder location="classpath:mysql.properties"/>
    
<util:properties id="settings" location="classpath:webConfig.properties"></util:properties>

Bean裏要加入mysql

xmlns:util="http://www.springframework.org/schema/util"

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd

 

@Component("webConfig")
public class WebConfig {
    
    @Value("#{settings['web.version']}")
    private String webVersion;

    public String getWebVersion() {
        return webVersion;
    }
    
}
        @Autowired
    private WebConfig webConfig;

        webConfig.getWebVersion();    
相關文章
相關標籤/搜索