相关疑难解决方法(0)

如何在spring boot中正确指定数据库模式?

在我的spring boot/hibernate应用程序中,我需要连接到属于"dbo"架构的Postgres数据库"ax2012_1".

我有以下application.properties:

# Database
db.driver: org.postgresql.Driver
db.url: jdbc:postgresql://localhost:5432/ax2012_1
db.username: my_user_name
db.password: my_password

spring.datasource.url= jdbc:postgresql://localhost:5432/ax2012_1
spring.datasource.username=my_user_name
spring.datasource.password=my_password
spring.datasource.schema=dbo 

spring.jpa.hibernate.ddl-auto=validate

# Hibernate
hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql: true
hibernate.hbm2ddl.auto: update
entitymanager.packagesToScan: com.mycompany.myproduct.data
Run Code Online (Sandbox Code Playgroud)

我的DatabaseConfig.java看起来像这样:

package com.uptake.symphony.data.configs;

import java.util.Properties;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
public class DatabaseConfig {

  // ------------------------
  // PUBLIC METHODS
  // ------------------------

  /**
   * DataSource definition for database connection. Settings are read from …
Run Code Online (Sandbox Code Playgroud)

java postgresql spring hibernate spring-boot

14
推荐指数
1
解决办法
4万
查看次数

标签 统计

hibernate ×1

java ×1

postgresql ×1

spring ×1

spring-boot ×1