为了账号安全,请及时绑定邮箱和手机立即绑定

Junit 测试中没有错误类型的合格 bean

Junit 测试中没有错误类型的合格 bean

弑天下 2021-06-16 16:12:25
我正在尝试使用 Spring Boot 2.0.3 版连接两个不同的数据源。一个指向 MySQL,另一个指向 PostgreSQL。MySQL 通过了所有测试。但是PostgreSQL的问题。这是应该映射到 PostgreSQL 的实体类。@Entity@Table(name = "order")@Data@NoArgsConstructor@AllArgsConstructorpublic class Order {  @Id  @GeneratedValue(strategy = GenerationType.IDENTITY)  private Long id;  private String productName;}这是 PostgreSQL 的配置类。@Configuration@EnableJpaRepositories(    basePackageClasses = Order.class,    entityManagerFactoryRef = "orderEntityManager",    transactionManagerRef = "orderTransactionManager")@PropertySource("classpath:application.properties")public class OrderConfig {@AutowiredEnvironment env;@Beanpublic DataSource getDataSource() {    DriverManagerDataSource dataSource = new DriverManagerDataSource();    dataSource.setDriverClassName(env.getProperty("order.datasource.class"));    dataSource.setUrl(env.getProperty("order.datasource.url"));    dataSource.setUsername(env.getProperty("order.datasource.username"));    dataSource.setPassword(env.getProperty("order.datasource.password"));    return dataSource;}@Bean(name = "orderEntityManager")public LocalContainerEntityManagerFactoryBean getEntityManager() {    LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean =            new LocalContainerEntityManagerFactoryBean();    localContainerEntityManagerFactoryBean.setDataSource(this.getDataSource());    localContainerEntityManagerFactoryBean.setPackagesToScan("com.seal.multipledatasource.entity.order");    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();    localContainerEntityManagerFactoryBean.setJpaVendorAdapter(hibernateJpaVendorAdapter);    Map<String, String> properties = new HashMap<>();    properties.put("hibernate.hbm2ddl.auto", env.getProperty("order.jpa.hibernate.ddl-auto"));    properties.put("hibernate.dialect", env.getProperty("order.jpa.hibernate.dialect"));    localContainerEntityManagerFactoryBean.setJpaPropertyMap(properties);}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 122 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信