注入应用上下文
@Autowired
protected ApplicationContext applicationContext;
通过应用上下文获取数据源配置
// 获取配置的数据源
DataSource dataSource = applicationContext.getBean(DataSource.class);
Connection connection = null;
try {
connection = dataSource.getConnection();
} catch (SQLException e) {
logger.error("获取数据库配置失败", e);
}