@Configuration与@ConfigurationProperties参数配置_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > @Configuration与@ConfigurationProperties参数配置

@Configuration与@ConfigurationProperties参数配置

 2019/3/12 18:33:05  zw7534313  程序员俱乐部  我要评论(0)
  • 摘要:参数配置1、application.propertiesjdbc.config.url=jdbc:mysql://127.0.0.1:3306/dbwback?useUnicode=true&characterEncoding=UTF-8jdbc.config.driver=com.mysql.jdbc.Driverjdbc.config.username=rootjdbc.config.password=pass01!2
  • 标签:配置
参数配置

1、application.properties
jdbc.config.url=jdbc:mysql://127.0.0.1:3306/dbwback?useUnicode=true&characterEncoding=UTF-8
jdbc.config.driver=com.mysql.jdbc.Driver
jdbc.config.username=root
jdbc.config.password=pass01!

2、
@Configuration
@ConfigurationProperties(prefix = "jdbc.config")
public class JdbcConfig {

private String url;
private String driver;
private String username;
private String password;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

public String toString() {
return "url="+url+",driver="+driver+",username="+username+",password="+password;
}
}

3.在controller中直接使用
@Controller("user_controller")
@RequestMapping("/user")
public class UserController{

@Autowired
JdbcConfig jdbcConfig;

}
发表评论
用户名: 匿名