Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Springboot应用程序从多个数据源读入新数据库_Java_Spring_Hibernate_Spring Boot - Fatal编程技术网

Java Springboot应用程序从多个数据源读入新数据库

Java Springboot应用程序从多个数据源读入新数据库,java,spring,hibernate,spring-boot,Java,Spring,Hibernate,Spring Boot,我正在创建一个新的Springboot应用程序,我希望实现以下目标 我需要有多个数据源(不同的只读数据库),从中读取信息。 我需要将收集到的信息存储在新的不同数据库中 因为我从中获取数据的数据库是只读的,所以我不打算使用Jpa或Hibernate 但是为了存储从获得的数据中实际生成的新对象,我希望使用Hibernate使其更简单 通过执行以下操作,我能够读取多个数据源 首先,我创建了一个CustomerClient: @Configuration public class CustomerCli

我正在创建一个新的Springboot应用程序,我希望实现以下目标

我需要有多个数据源(不同的只读数据库),从中读取信息。 我需要将收集到的信息存储在新的不同数据库中

因为我从中获取数据的数据库是只读的,所以我不打算使用Jpa或Hibernate

但是为了存储从获得的数据中实际生成的新对象,我希望使用Hibernate使其更简单

通过执行以下操作,我能够读取多个数据源

首先,我创建了一个CustomerClient

@Configuration
public class CustomerClient {

    @Bean(name = "customerDataSource")
    @ConfigurationProperties("stats-collector.clients.customers")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Customer> getCustomers() {
        String sql = "SELECT * FROM customer";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new CustomerRowMapper());
    }

    public static class CustomerRowMapper implements RowMapper<Customer> {
        @Override
        public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Customer(rs.getLong("id"), rs.getString("name"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Configuration
public class ProductClient {

    @Bean(name = "productDataSource")
    @ConfigurationProperties("stats-collector.clients.products")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Product> getProducts() {
        String sql = "SELECT * FROM product";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new ProductRowMapper());
    }

    public static class ProductRowMapper implements RowMapper<Product> {
        @Override
        public Product mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Product(rs.getLong("id"), rs.getString("name"), rs.getDouble("price"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Service
public class CustomerStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(CustomerStatsCollectorService.class);

    @Autowired
    private CustomerClient customerClient;

    @Autowired
    private CustomerRepository customerRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Customer> customers = customerClient.getCustomers();
        logger.info("Collected information from customers database:: Customers fetched - {}", customers.size());
        customerRepository.saveAll(customers);
    }
}
@Service
public class ProductStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(ProductStatsCollectorService.class);

    @Autowired
    private ProductClient productClient;

    @Autowired
    private ProductRepository productRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Product> products = productClient.getProducts();
        logger.info("Collected information from products database :: Products fetched - {}", products.size());
        productRepository.saveAll(products);
    }
}
@Entity
public class Customer implements Serializable {

    @Id
    private Long id;

    private String name;

    private Timestamp timeCreated;

    public Customer() {
    }

    public Customer(Long id, String name, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Customer {"
                + "id: " + id
                + ", name: " + name
                + "}";
    }
}
@Entity
public class Product implements Serializable {

    @Id
    private Long id;

    private String name;

    private Double price;

    private Timestamp timeCreated;

    public Product() {
    }

    public Product(Long id, String name, Double price, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Double getPrice() {
        return this.price;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Target {"
                + "id: " + id
                + ", name: " + name
                + ", price: " + price
                + "}";
    }
}
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
public interface ProductRepository extends CrudRepository<Product, Long> {
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>amc-stats-collector-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AMC Stats Collector</name>
    <description>AMC Stats Collector</description>

    <parent>
        <groupId>com.mulesoft.amc</groupId>
        <artifactId>amc-stats-collector</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
产品

@Configuration
public class CustomerClient {

    @Bean(name = "customerDataSource")
    @ConfigurationProperties("stats-collector.clients.customers")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Customer> getCustomers() {
        String sql = "SELECT * FROM customer";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new CustomerRowMapper());
    }

    public static class CustomerRowMapper implements RowMapper<Customer> {
        @Override
        public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Customer(rs.getLong("id"), rs.getString("name"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Configuration
public class ProductClient {

    @Bean(name = "productDataSource")
    @ConfigurationProperties("stats-collector.clients.products")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Product> getProducts() {
        String sql = "SELECT * FROM product";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new ProductRowMapper());
    }

    public static class ProductRowMapper implements RowMapper<Product> {
        @Override
        public Product mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Product(rs.getLong("id"), rs.getString("name"), rs.getDouble("price"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Service
public class CustomerStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(CustomerStatsCollectorService.class);

    @Autowired
    private CustomerClient customerClient;

    @Autowired
    private CustomerRepository customerRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Customer> customers = customerClient.getCustomers();
        logger.info("Collected information from customers database:: Customers fetched - {}", customers.size());
        customerRepository.saveAll(customers);
    }
}
@Service
public class ProductStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(ProductStatsCollectorService.class);

    @Autowired
    private ProductClient productClient;

    @Autowired
    private ProductRepository productRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Product> products = productClient.getProducts();
        logger.info("Collected information from products database :: Products fetched - {}", products.size());
        productRepository.saveAll(products);
    }
}
@Entity
public class Customer implements Serializable {

    @Id
    private Long id;

    private String name;

    private Timestamp timeCreated;

    public Customer() {
    }

    public Customer(Long id, String name, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Customer {"
                + "id: " + id
                + ", name: " + name
                + "}";
    }
}
@Entity
public class Product implements Serializable {

    @Id
    private Long id;

    private String name;

    private Double price;

    private Timestamp timeCreated;

    public Product() {
    }

    public Product(Long id, String name, Double price, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Double getPrice() {
        return this.price;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Target {"
                + "id: " + id
                + ", name: " + name
                + ", price: " + price
                + "}";
    }
}
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
public interface ProductRepository extends CrudRepository<Product, Long> {
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>amc-stats-collector-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AMC Stats Collector</name>
    <description>AMC Stats Collector</description>

    <parent>
        <groupId>com.mulesoft.amc</groupId>
        <artifactId>amc-stats-collector</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
最后是我的两个存储库:

客户存储库

@Configuration
public class CustomerClient {

    @Bean(name = "customerDataSource")
    @ConfigurationProperties("stats-collector.clients.customers")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Customer> getCustomers() {
        String sql = "SELECT * FROM customer";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new CustomerRowMapper());
    }

    public static class CustomerRowMapper implements RowMapper<Customer> {
        @Override
        public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Customer(rs.getLong("id"), rs.getString("name"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Configuration
public class ProductClient {

    @Bean(name = "productDataSource")
    @ConfigurationProperties("stats-collector.clients.products")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Product> getProducts() {
        String sql = "SELECT * FROM product";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new ProductRowMapper());
    }

    public static class ProductRowMapper implements RowMapper<Product> {
        @Override
        public Product mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Product(rs.getLong("id"), rs.getString("name"), rs.getDouble("price"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Service
public class CustomerStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(CustomerStatsCollectorService.class);

    @Autowired
    private CustomerClient customerClient;

    @Autowired
    private CustomerRepository customerRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Customer> customers = customerClient.getCustomers();
        logger.info("Collected information from customers database:: Customers fetched - {}", customers.size());
        customerRepository.saveAll(customers);
    }
}
@Service
public class ProductStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(ProductStatsCollectorService.class);

    @Autowired
    private ProductClient productClient;

    @Autowired
    private ProductRepository productRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Product> products = productClient.getProducts();
        logger.info("Collected information from products database :: Products fetched - {}", products.size());
        productRepository.saveAll(products);
    }
}
@Entity
public class Customer implements Serializable {

    @Id
    private Long id;

    private String name;

    private Timestamp timeCreated;

    public Customer() {
    }

    public Customer(Long id, String name, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Customer {"
                + "id: " + id
                + ", name: " + name
                + "}";
    }
}
@Entity
public class Product implements Serializable {

    @Id
    private Long id;

    private String name;

    private Double price;

    private Timestamp timeCreated;

    public Product() {
    }

    public Product(Long id, String name, Double price, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Double getPrice() {
        return this.price;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Target {"
                + "id: " + id
                + ", name: " + name
                + ", price: " + price
                + "}";
    }
}
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
public interface ProductRepository extends CrudRepository<Product, Long> {
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>amc-stats-collector-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AMC Stats Collector</name>
    <description>AMC Stats Collector</description>

    <parent>
        <groupId>com.mulesoft.amc</groupId>
        <artifactId>amc-stats-collector</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
Myapplication.yml配置文件:

stats-collector:
  clients:
    customers:
      jdbc-url: jdbc:postgresql://localhost:5432/customersDatabase
      username: postgres
      password:
    products:
      jdbc-url: jdbc:postgresql://localhost:5432/productsDatabase
      username: postgres
      password:

spring:
  datasource:
    jdbc-url: jdbc:postgresql://localhost:5432/testdb
    username: postgres
    password:
  jpa:
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true
        id:
          new_generator_mappings: false
    hibernate:
      ddl-auto: create
启动应用程序后,出现以下错误:

com.test.stats.collector.service.CustomerStatsCollectorService中的字段customerRepository需要名为“entityManagerFactory”的bean,但找不到该bean。 行动: 考虑在您的定义中定义一个名为“EntIdMaulePrimeC工厂”的bean 配置 进程已完成,退出代码为1

应用程序从不同的数据源收集信息,直到我添加了jpa和存储库来存储这些数据。我不知道如何解决这个问题,因为我只想从Products数据库和Customers数据库中读取对象,而只想使用Hibernate将数据存储到新数据库中

最后,我的pom.xml

@Configuration
public class CustomerClient {

    @Bean(name = "customerDataSource")
    @ConfigurationProperties("stats-collector.clients.customers")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Customer> getCustomers() {
        String sql = "SELECT * FROM customer";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new CustomerRowMapper());
    }

    public static class CustomerRowMapper implements RowMapper<Customer> {
        @Override
        public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Customer(rs.getLong("id"), rs.getString("name"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Configuration
public class ProductClient {

    @Bean(name = "productDataSource")
    @ConfigurationProperties("stats-collector.clients.products")
    public DataSource getDataSource() {
        return DataSourceBuilder.create().build();
    }

    public List<Product> getProducts() {
        String sql = "SELECT * FROM product";

        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

        return jdbcTemplate.query(sql, new ProductRowMapper());
    }

    public static class ProductRowMapper implements RowMapper<Product> {
        @Override
        public Product mapRow(ResultSet rs, int rowNum) throws SQLException {

            return new Product(rs.getLong("id"), rs.getString("name"), rs.getDouble("price"), new Timestamp(System.currentTimeMillis()));
        }
    }
}
@Service
public class CustomerStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(CustomerStatsCollectorService.class);

    @Autowired
    private CustomerClient customerClient;

    @Autowired
    private CustomerRepository customerRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Customer> customers = customerClient.getCustomers();
        logger.info("Collected information from customers database:: Customers fetched - {}", customers.size());
        customerRepository.saveAll(customers);
    }
}
@Service
public class ProductStatsCollectorService {

    private static final Logger logger = LoggerFactory.getLogger(ProductStatsCollectorService.class);

    @Autowired
    private ProductClient productClient;

    @Autowired
    private ProductRepository productRepository;

    @Scheduled(cron = "0 * * * * ?")
    public void collectInformation() {
        List<Product> products = productClient.getProducts();
        logger.info("Collected information from products database :: Products fetched - {}", products.size());
        productRepository.saveAll(products);
    }
}
@Entity
public class Customer implements Serializable {

    @Id
    private Long id;

    private String name;

    private Timestamp timeCreated;

    public Customer() {
    }

    public Customer(Long id, String name, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Customer {"
                + "id: " + id
                + ", name: " + name
                + "}";
    }
}
@Entity
public class Product implements Serializable {

    @Id
    private Long id;

    private String name;

    private Double price;

    private Timestamp timeCreated;

    public Product() {
    }

    public Product(Long id, String name, Double price, Timestamp timeCreated) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.timeCreated = timeCreated;
    }

    public Long getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public Double getPrice() {
        return this.price;
    }

    public Timestamp getTimeCreated() {
        return timeCreated;
    }

    @Override
    public String toString() {
        return "Target {"
                + "id: " + id
                + ", name: " + name
                + ", price: " + price
                + "}";
    }
}
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
public interface ProductRepository extends CrudRepository<Product, Long> {
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>amc-stats-collector-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>AMC Stats Collector</name>
    <description>AMC Stats Collector</description>

    <parent>
        <groupId>com.mulesoft.amc</groupId>
        <artifactId>amc-stats-collector</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
统计数据收集器服务
1.0.0-SNAPSHOT
罐子
AMC统计数据采集器
AMC统计数据采集器
com.mulesoft.amc
amc统计数据采集器
1.0.0-SNAPSHOT
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧靴起动器
org.springframework.boot
弹簧靴启动器jdbc
org.postgresql
postgresql
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
springbootmaven插件
org.apache.maven.plugins
maven checkstyle插件

问题在于您使用的是Crudepository,这需要符合JPA的框架。您可能对……感兴趣。

谢谢您的快速回答!是的,我确实想要一个JPA兼容的框架。仅用于将收集的数据存储在新数据库(testdb)中。我不希望只读数据库使用符合JPA的框架不确定这是否能解决您的问题,但我认为您必须定义两个实体管理器。再次感谢您的快速提问。我读了这篇文章,现在了解了如何创建两个实体经理。我不明白的是如何在我的积垢上使用它。。。我认为Springboot的所有文档都不完整,谢谢你们的回答。其实我需要的是不同的。我需要将数据库A和数据库B中的数据读入两个对象(A和B)。该数据(A和B)必须使用HibernateSo存储在数据库C中。无论如何,您必须创建3个数据源,并使用相应的存储库来获取n merge,然后持久化。。