SpringCloud配置acyive的profiles

阅读 41

2022-05-17


   application.yml

spring:
profiles:
active: pre

  application-dev.yml

junzizhibang:
url: dev.junzizhibang.com
@RestController
public class IndexController {
@Value("${junzizhibang.url}")
private String url;

@RequestMapping("/getUrl")
public String getUrl() {
return url;
}
}

JDBC的SPringCloud的配置

@Service
public class UserService {

@Autowired
private JdbcTemplate jdbcTemplate;


public boolean addUser(String userName, Integer age) {
int update = jdbcTemplate.update("insert into users values(null,?,?);", userName, age);
return update > 0 ? true : false;
}
}

yaml的数据库配置:

spring:
datasource:
url: jdbc:mysql://localhost:3306/test
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver



精彩评论(0)

0 0 举报