SQL Server未返回响应

时间:2018-07-18 11:42:36

标签: sql-server hibernate spring-boot

我收到错误消息: com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法通过使用安全套接字层(SSL)加密建立到SQL Server的安全连接。错误:“ SQL Server未返回响应。连接已关闭。”

休眠配置:

members

application.properties:

Select

pom.xml:

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "sqlUserEntityManagerFactory")
public class MR2HibernateDataConfig {

    @Value("${sql.server.dialect}")
    private String dialect;

    @Bean(name = "sqlUserDataSource")
    @ConfigurationProperties(prefix = "mr.datasource")
    public DataSource sqlUserDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "sqlUserEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean sqlUserEntityManagerFactory(
            EntityManagerFactoryBuilder builder,
            @Qualifier("sqlUserDataSource") DataSource dataSource) {
        Map<String, String> properties = new HashMap<>();
        properties.put("hibernate.dialect", dialect);
        return builder
                .dataSource(dataSource)
                .packages("ru.connection.db.model.mr")
                .persistenceUnit("mr")
                .properties(properties)
                .build();
    }

    @Bean(name = "sqlUserTransactionManager")
    public JpaTransactionManager sqlUserTransactionManager(
            @Qualifier("sqlUserEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }
}

SQLServerException:

mr.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
mr.datasource.url=jdbc:sqlserver://server:1433;databaseName=test;
mr.datasource.username=username
mr.datasource.password=userpassword
sql.server.dialect=org.hibernate.dialect.SQLServer2008Dialect

openssl s_client-连接服务器:1433

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
</parent>
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>

你怎么看?

1 个答案:

答案 0 :(得分:0)

我将Java版本从jdk-8.172更改为jdk-8.152,并且对我有用。