av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java - 就配置了一個(gè)數(shù)據(jù)源,為什么提示 there is more than one bean of "DataSource" type

瀏覽:147日期:2023-10-22 15:07:51

問(wèn)題描述

java - 就配置了一個(gè)數(shù)據(jù)源,為什么提示 there is more than one bean of "DataSource" type

我好像就配置了一個(gè)數(shù)據(jù)源,為什么注入的時(shí)候會(huì)提示有多個(gè)?

package com.example.demo.config;import org.apache.commons.dbcp.BasicDataSource;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.PropertySource;@Configuration@PropertySource('classpath:application.properties')public class DataSourceConfiguration { @Value('${jdbc.driver}') private String driver; @Value('${jdbc.url}') private String url; @Value('${jdbc.username}') private String username; @Value('${jdbc.password}') private String password; @Value('${jdbc.maxActive}') private int maxActive; @Value('${jdbc.maxIdel}') private int maxIdel; @Value('${jdbc.maxWait}') private long maxWait; @Bean //應(yīng)該就這一個(gè)吧 public BasicDataSource dataSource(){BasicDataSource dataSource = new BasicDataSource();dataSource.setDriverClassName(driver);dataSource.setUrl(url);dataSource.setUsername(username);dataSource.setPassword(password);dataSource.setMaxActive(maxActive);dataSource.setMaxIdle(maxIdel);dataSource.setMaxWait(maxWait);dataSource.setValidationQuery('SELECT 1');dataSource.setTestOnBorrow(true);return dataSource; }}

package com.example.demo.config;import org.apache.ibatis.session.SqlSessionFactory;import org.mybatis.spring.SqlSessionFactoryBean;import org.mybatis.spring.SqlSessionTemplate;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.jdbc.datasource.DataSourceTransactionManager;import org.springframework.transaction.PlatformTransactionManager;import org.springframework.transaction.annotation.EnableTransactionManagement;import org.springframework.transaction.annotation.TransactionManagementConfigurer;import javax.annotation.Resource;import javax.annotation.Resources;import javax.sql.DataSource;@Configuration@EnableTransactionManagementpublic class MyBatisConfig implements TransactionManagementConfigurer { @Autowired //這里怎么不能用@Autowired,用Resource倒是可以 private DataSource dataSource; @Override public PlatformTransactionManager annotationDrivenTransactionManager() {return new DataSourceTransactionManager(dataSource); } @Bean(name = 'sqlSessionFactory') public SqlSessionFactory sqlSessionFactoryBean() {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);try { return bean.getObject();} catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e);} } @Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory); }}

問(wèn)題解答

回答1:

運(yùn)行一下即可,看報(bào)錯(cuò)信息

標(biāo)簽: java
主站蜘蛛池模板: 波多野结衣精品在线 | 色在线看 | 中文字幕一区二区三区四区 | 精品视频久久久 | 一区二区三区不卡视频 | 欧美一区二区三区在线观看 | 欧美精品 在线观看 | 91成人免费电影 | 日韩色在线 | 激情一区二区三区 | 亚洲人成一区二区三区性色 | 午夜影院 | 91网站在线看 | 久久精品在线播放 | 凹凸日日摸日日碰夜夜 | 欧美一区在线视频 | 青青草av网站 | 美女久久久 | 奇米超碰 | 亚洲视频免费 | 日日射影院 | 色婷婷婷婷色 | 午夜三级视频 | 成人三级在线观看 | 国产夜恋视频在线观看 | 日韩一区在线视频 | 99re热精品视频国产免费 | 一区二区在线免费观看 | 天堂网av在线 | 中文字幕在线视频网站 | 波多野结衣中文字幕一区二区三区 | 老牛影视av一区二区在线观看 | 人人干人人艹 | 四虎影院免费在线 | 福利精品| 91精品国产综合久久久久 | 免费一级欧美在线观看视频 | 成年人在线观看视频 | 国产精品成人久久久久 | 久久久久久久久久久一区二区 | 五月激情综合网 |