我在最近的Springboot 2.3版本中遇到问题。
我有以下配置类:
package name.defance.springbootdemo.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@Configuration
public class SampleConfig {
@Autowired
public SampleConfig(DataSource dataSource) {
System.out.println("DATASOURCE: " + dataSource);
this.dataSource = dataSource;
}
final private DataSource dataSource;
}
对于版本为2.2.7
,我具有以下输出:
<... truncated output ...>
2020-05-18 17:57:33.872 INFO 2081 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-18 17:57:33.873 INFO 2081 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.34]
2020-05-18 17:57:33.950 INFO 2081 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-18 17:57:33.950 INFO 2081 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2113 ms
2020-05-18 17:57:34.511 INFO 2081 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-18 17:57:34.555 INFO 2081 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.15.Final
2020-05-18 17:57:34.686 INFO 2081 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-18 17:57:34.801 INFO 2081 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-18 17:57:34.901 INFO 2081 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-18 17:57:34.922 INFO 2081 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-05-18 17:57:35.405 INFO 2081 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-18 17:57:35.411 INFO 2081 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-18 17:57:35.463 WARN 2081 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
DATASOURCE: HikariDataSource (HikariPool-1)
<... truncated output ...>
[版本为2.3.0.RELEASE
,我有以下内容:
<... truncated output ...>
2020-05-18 17:52:02.183 INFO 352 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-18 17:52:02.184 INFO 352 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-05-18 17:52:02.249 INFO 352 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-18 17:52:02.249 INFO 352 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2453 ms
2020-05-18 17:52:02.669 INFO 352 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
DATASOURCE: HikariDataSource (null)
2020-05-18 17:52:02.720 INFO 352 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-18 17:52:02.755 INFO 352 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.15.Final
2020-05-18 17:52:02.862 INFO 352 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-18 17:52:02.957 INFO 352 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-18 17:52:03.066 INFO 352 --- [ task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-18 17:52:03.081 INFO 352 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-05-18 17:52:03.526 INFO 352 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-18 17:52:03.534 INFO 352 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-18 17:52:03.736 WARN 352 --- [ task-2] o.s.b.d.a.OptionalLiveReloadServer : Unable to start LiveReload server
<... truncated output ...>
两者之间的唯一区别是(在pom.xml
中:]]
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
vs
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
因此,在新发行版中,数据源Bean是在单独的线程中配置的,而我的配置Bean接收到尚未配置的数据源Bean(空)。
我在发行说明中找不到任何有关配置流程更改的参考。这里出了什么问题,为什么我的代码停止工作?
UPDATE
。我用Spring初始化器再次再现了这个问题。选择的选项:Java 14,执行器,jdbc,web,devtools,postgres db驱动程序应用程序属性包含所有正确的连接数据(已在其他旧弹簧项目中验证)。它的唯一内容是:
:项目存储库https://github.com/defance/datasource-demospring.datasource.url=jdbc:postgresql://localhost:15432/insurance-demo spring.datasource.username=postgres spring.datasource.password=postgresPWD server.port=8080
更新
我在最近的Springboot 2.3版本中遇到问题。我有以下配置类:package name.defance.springbootdemo.security;导入org.springframework.beans.factory.annotation.Autowired; ...
似乎可以将'spring-boot-starter-data-jpa'添加到依赖项集中,以使hikari池重新回到以前的位置。