DruidDataSourceWrapper必须要获取到环境变量否则抛异常
- Dominant language
- Java
- Stars
- 28.2k
- Forks
- 8.6k
- PR merge metrics
- No merged PRs in 30d
Description
已经在`applicationContext.xml`中配置了datasource,没有在`application.yml`中配置`spring.datasource`属性
```xml
```
但是`DruidDataSourceAutoConfigure`构造`DruidDataSourceWrapper`,其中必须要获取环境变量
```java
@Override
public void afterPropertiesSet() throws Exception {
//if not found prefix 'spring.datasource.druid' jdbc properties ,'spring.datasource' prefix jdbc properties will be used.
if (super.getUsername() == null) {
super.setUsername(basicProperties.determineUsername());
}
```
没有就会抛异常`Method threw 'org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException' exception.`
最终导致
```
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles uat are currently active).
```
现在必须要加注解`@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)`才能正常启动使用,但是监控Servlet就不会自动装配了
Contributor guide
Research direction
Reproduce the startup failure with the datasource bean in applicationContext.xml and without spring.datasource properties. Start by reading DruidDataSourceAutoConfigure, DruidDataSourceWrapper, and its afterPropertiesSet method; done means the XML-configured datasource starts without the exclusion while the monitoring Servlet remains auto-configured.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100