【发布时间】:2019-04-16 06:31:40
【问题描述】:
我想在一个 Spring Boot 应用程序中配置两个数据库,一开始我尝试使用一个,但出现错误。
@Configuration
public class DatabaseConfiguration {
@Bean(name = "user")
@ConfigurationProperties(prefix = "spring.user")
public DataSource createProductServiceDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "jdbcuser")
@Autowired
public JdbcTemplate createJdbcTemplate_ProductService(@Qualifier("user") DataSource productServiceDS) {
return new JdbcTemplate(productServiceDS);
}
}
dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
spring.jpa.hibernate.ddl-auto=none
spring.user.url=jdbc:mysql://ip address:port/testdb
spring.user.username=username
spring.user.password=password
server.port=port
spring.user.driver-class-name=com.mysql.jdbc.Driver
@RestController
@Qualifier("jdbcuser")
public class Failed_Status {
@Autowired
JdbcTemplate jdbcTemplate;
@GetMapping("/select")
public List<User> getList()
{
String sql="select * from Customerinfo where status like 'F%'";
List<User> u=new ArrayList<User>();
u= jdbcTemplate.query(sql,new UserRowMapper());
System.out.println(u);
return u;
}
}
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded data source could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
由于我是 Spring Boot 新手,我无法找到如何使用多个数据库。请让我知道我需要做哪些更改才能成功运行该程序?
【问题讨论】:
标签: java spring spring-boot jdbctemplate multiple-databases