spring-boot - Spring Boot中的MS SQL Server数据源Java配置

标签 spring-boot jpa datasource spring-java-config mssql-jdbc

我正在尝试为我的 ms sql 服务器使用 java 配置,但无法找到有关如何在配置类中将其定义为 Bean 的任何信息。 我之前用过Oracle,配置起来非常简单。我曾经为 Oracle 编写过这段代码。

@Bean
DataSource dataSource() throws SQLException {

    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setUser(username);
    dataSource.setPassword(password);
    dataSource.setURL(url);
    dataSource.setImplicitCachingEnabled(true);
    dataSource.setFastConnectionFailoverEnabled(true);
    return dataSource;
}

到目前为止,我正在使用 application.properties,但我不想继续使用此文件。

最佳答案

您可以使用专用SQLServerDataSource就像您对 Oracle 所做的那样:

@Bean
DataSource dataSource() throws SQLException {

    SQLServerDataSource dataSource = new SQLServerDataSource();
    dataSource.setUser(username);
    dataSource.setPassword(password);
    dataSource.setURL(url);
    return dataSource;
}

关于spring-boot - Spring Boot中的MS SQL Server数据源Java配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49819995/

相关文章:

spring - Spring MVC 中 @RequestParam 的自定义转换器

java - JPA OneToMany 双向

java - 使用@Transactional时EntityManager.persist()不插入数据

xml - BIRT 不显示 base64 编码的图像

java - 如何查看server.xml中的tomcat数据源连接池

java - RestTemplate/HttpClient 更改 Spring Boot 1.5 -> 2.1

mysql - spring boot + JPA + mysql,无法检索结果集

java - 如何为具有 n :m relationship and multiple primary keys 的 MySQL 数据库表配置实体类

java - Hibernate 映射 - 如何连接三个表

C# databound ComboBox 更改其他控件中的数据