【问题标题】:Spring Boot application pending when trying to persist to SQL Server尝试持久保存到 SQL Server 时,Spring Boot 应用程序挂起
【发布时间】:2017-02-07 16:40:51
【问题描述】:

我有一个 Spring Boot 应用程序,我正在尝试使用它来将一些数据持久化到在端口 1434 上作为 Docker 容器(仅用于开发目的)运行的 MSSQL 实例。

我有一个从CrudRepository 实现的@Repository 类:

@Repository
public interface BookingRepository extends CrudRepository<Booking, Integer> {

}

然后是 @Service 课程,我想尝试并坚持预订:

public void process(Booking booking) throws IOException {
    bookingCreatedRepository.save(booking);
    log.info("After the save"); // this line is never reached
}

问题是上面的服务 sn-p 中的log.info 行永远不会到达。如果我打开调试器并尝试通过对该语句的评估来强制保存,则操作永远不会完成。

没有例外,没有超时,什么都没有。应用程序会在此时停止。

我的application.properties 文件:

spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.username=sa
spring.datasource.password=Password12#
spring.datasource.url=jdbc:sqlserver://localhost:1434;databaseName=Reporting
spring.jpa.database=sql_server
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.database-platform=SQL_SERVER

另外,我的依赖项如下:

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.10</version>
</dependency>

【问题讨论】:

    标签: java sql-server spring


    【解决方案1】:

    终于弄明白了,但这与我所描述的本身无关。

    我通过官方的 AWS Kinesis SDK 使用 AWS Kinesis,这显然阻塞了 .save() 应该发生的线程。我想这个故事的寓意是检查线程是否被阻塞。

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 2014-06-18
      • 1970-01-01
      • 2013-01-08
      • 2018-01-01
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 2021-10-28
      相关资源
      最近更新 更多