@ImportResource导入文件、@Value

来源:互联网 发布:大数据展示平台 编辑:程序博客网 时间:2024/05/16 00:34

@Configuration
@ImportResource(“classpath:config.xml”)
public class StoreConfig {

@Value(“${url}”)
private String url;
/* 为什么会在username前加jdbc*/
/原因如果单是username,系统会认为这是系统登录用户名/
@Value(“${jdbc.username}”)
private String username;

@Value("${password}")private String password;@Beanpublic MyDriverManager myDriverManager() {    return new MyDriverManager(url, username, password);}

config.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:context="http://www.springframework.org/schema/context"    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context.xsd" >    <context:property-placeholder location="classpath:/config.properties"/></beans>

config.properties

jdbc.password=rootjdbc.url=jdbc\:mysql\://127.0.0.1.8\:3306/databasejdbc.username=root
0 0
原创粉丝点击