我对spring boot很新,我想为我的项目创建一个多数据源.这是我目前的情况.我有两个用于多个数据库的实体包.让我们说吧
com.test.entity.db.mysql ; for entities that belong to MySql
com.test.entity.db.h2 ; for entities that belong to H2 Databases
所以,目前我有两个实体类
UserMySql.java
@Entity
@Table(name="usermysql")
public class UserMysql{
    @Id
    @GeneratedValue
    public int id;
    public String name;
}
UserH2.java
@Entity
@Table(name="userh2")
public class Userh2 {
    @Id
    @GeneratedValue
    public int id;
    public String name;
}
我想实现一个配置,如果我从UserMySql创建用户,它将被保存到MySql数据库,如果我从Userh2创建用户,它将被保存到H2数据库.所以,我也有两个DBConfig,比方说MySqlDbConfig和H2DbConfig.
(com.test.model是我将放置我的Repositories类的包.它将在下面定义)
MySqlDbConfig.java
@Configuration
@EnableJpaRepositories(
    basePackages="com.test.model",
    entityManagerFactoryRef = "mysqlEntityManager")
public class MySqlDBConfig {
@Bean
@Primary
@ConfigurationProperties(prefix="datasource.test.mysql")
public DataSource mysqlDataSource(){
    return DataSourceBuilder
            .create()
            .build();
}
@Bean(name="mysqlEntityManager")
public LocalContainerEntityManagerFactoryBean mySqlEntityManagerFactory(
        EntityManagerFactoryBuilder …已解决: 我的解决方案:我从DatabaseConfig.java中删除了dataSource()方法.然后,应用程序成功启动:)
我刚刚将Spring Boot项目从1.5.x更新到2.0.0.在更新之前,此应用程序正常工作但在更新后,我收到的一些错误如下.有什么问题,你能帮帮我吗?
我在项目中使用PostgreSQL,Hibernate,JPA.
我也试过这个,但它对我不起作用.
谢谢你的时间 :)
这是问题:
2018-03-03 23:19:37.934 ERROR 42323 --- [           main] com.zaxxer.hikari.HikariConfig           : HikariPool-1 - dataSource or dataSourceClassName or jdbcUrl is required.
2018-03-03 23:19:37.938  WARN 42323 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating …我试图在Spring Batch中配置几个数据源.在启动时,Spring Batch抛出以下异常:
To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2  
批量配置的代码段
@Configuration
@EnableBatchProcessing 
public class BatchJobConfiguration {
    @Primary
    @Bean(name = "baseDatasource")
    public DataSource dataSource() {
         // first datasource definition here
    }
    @Bean(name = "secondaryDataSource")
    public DataSource dataSource2() {
         // second datasource definition here
    }
    ...
}
不知道为什么我看到这个异常,因为我已经看到一些基于xml的Spring批处理配置声明了多个数据源.我使用Spring Batch核心版本3.0.1.RELEASE与Spring Boot版本1.1.5.RELEASE.任何帮助将不胜感激.
我在下划线中有数据库字段.我在camelcase中有实体字段.我无法改变其中任何一个.
有什么东西,也许是类级注释,我可以用来默认实体列名注释到camelcase等价物?
例如,我有一个像这样的实体:
@Entity
public class AuthorisationEntity {
    @Column(name = "non_recoverable")
    private BigDecimal nonRecoverable;
    @Column(name = "supplier_recoverable")
    private BigDecimal supplierRecoverable;
    @Column(name = "refund_amount")
    private BigDecimal refundAmount;
}
我梦见这个:
@Entity
@DatabaseIsUnderscoreAndThisAnnotationConvertsThemToCamelCaseByDefault
public class AuthorisationEntity {
    private BigDecimal nonRecoverable;
    private BigDecimal supplierRecoverable;
    private BigDecimal refundAmount;
}
为什么 SpringChainedTransactionManager被弃用了?Spring 是否提供任何替代库来支持多个事务管理器?
我的用例:- 我们正在构建一个连接到两个数据源(db1 和 db2)的 Spring Boot 应用程序,它对两个数据库(db1 和 db2)执行插入操作。我们的要求是这样的:插入 -> DB1 -> 成功插入 -> DB2 -> 错误回滚 DB1
目前,我们正在使用ChaninedTransactionManager并且它按预期工作,但我可以看到 lib 已被弃用。那么,只是想确保使用它是否安全,或者 Spring 是否提供了任何我们可以用来替代它的替代库?
我对Spring Boot应用程序有问题。我想在我的Spring启动应用程序中连接MongoDB数据库和MySql数据库。我想知道是否有可能,在积极的情况下,我如何进行这种多重连接。我已经基于Mysql和Post的示例进行了尝试,但没有成功。所以我想知道是否有人有一个简单的例子来了解该方法。谢谢
我有一个 Spring Boot 应用程序,它将与两个数据库(Cassandra 和 DB2)进行通信。我将在此应用程序中使用 spring 数据。是否适用于只在application.yml文件中配置数据源,而不需要编写java代码?如果是这样,我如何指定每种语言的方言?
注意:此应用程序使用 spring-data-cassandra 作为 cassandra 数据库,使用 spring-data-jpa 作为 db2 数据库。
例如:
spring:
  datasource:
    url: jdbc:db2://myRemoteHost:portNumber/MyDBName
    username: username
    password: password
    driver-class-name: com.ibm.db2.jcc.DB2Driver
  data:
    cassandra:
      cluster-name: cluster name
      keyspace-name: keyspace name
      port: myPortNumber
      contact-points: host1.com
      username: username
      password: password
注意:此问题与Spring Boot 配置和使用两个数据源不同。我的问题是知道它是否适用于仅在 application.yml 文件中配置数据源而无需手动执行,而另一个问题解释了如何手动执行此操作。
I'm new to stackoverflow, but read tons of posts here and now stuck.my application.properties is read, but the portion for configuring hikaricp is ignored/has no effect.
I read https://www.javadevjournal.com/spring-boot/spring-boot-hikari/ and folowed those steps there, still any success.
pom.xml
    <dependencies>  
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>5.4.10.Final</version>
        <exclusions>
            <exclusion>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache</artifactId>
            </exclusion>
        </exclusions>
    </dependency>    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jcache</artifactId>
        <version>5.4.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>3.6.3</version>
    </dependency>        
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
            </exclusion>                
        </exclusions>
        <version>2.2.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
         <exclusion>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
          </exclusion>
        </exclusions> …我正在使用Spring Boot 1.5.18.RELEASE。
我使用以下链接关注了多个数据源:
但是当我在同一服务器上有数据源时,它可以工作。
这是我的情况:
在上述情况下,Spring Boot应用程序仅尝试检查服务器1中的表,结果我得到了sql异常之类的信息
SqlExceptionHelper - SQL Error: 1146, SQLState: 42S02
SqlExceptionHelper - Table 'datasource2.table2' doesn't exist
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 
'datasource2.table2' doesn't exist
如何解决这个问题?
hibernate spring-data-jpa spring-boot multi-database-connections
有没有人在 Spring Boot 应用程序中成功配置了两个具有不同数据源的 hikari 连接池?如何使用 application.properties 来做到这一点?
spring-boot ×8
java ×5
spring ×4
hibernate ×2
hikaricp ×2
spring-data ×2
annotations ×1
config ×1
datasource ×1
db2 ×1
informix ×1
mongodb ×1
mysql ×1
spring-batch ×1
spring-mvc ×1
yaml ×1