在我的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)