亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

java - 就配置了一個數據源,為什么提示 there is more than one bean of "DataSource" type

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

問題描述

java - 就配置了一個數據源,為什么提示 there is more than one bean of "DataSource" type

我好像就配置了一個數據源,為什么注入的時候會提示有多個?

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 //應該就這一個吧 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); }}

問題解答

回答1:

運行一下即可,看報錯信息

標簽: java
主站蜘蛛池模板: 性视频网站视频免费 | 老湿机一区午夜精品免费福利 | 中文字幕第98页小明免费 | 国产视频你懂得 | 俺来也久久| 91在线看视频 | www.毛片在线观看 | 国产成人一区二区三区影院免费 | 免费黄色在线看 | 最新99国产成人精品视频免费 | 九九精品免费 | 亚洲综合网在线观看 | 毛片网在线 | a级亚洲片精品久久久久久久 | 国产三级电影网址 | 天天影视欧美综合在线观看 | 国产一区二区三区在线 | 国产精品一级二级三级 | 欧美综合色区 | 99久久er热在这里都是精品66 | 国产午夜精品不卡视频 | 九九热视频这里只有精品 | 久久久这里只有精品加勒比 | 中国国产一国产一级毛片视频 | 久久亚洲精品中文字幕亚瑟 | 韩国r级福利视频在线观看网站 | 黄色在线观看视频网站 | 国产一级αv片免费观看 | 噜噜噜在线视频 | 国产主播第一页 | 黄色毛片在线观看 | 亚洲欧美在线观看 | 国产成人性毛片aaww | 女人色毛片女人色毛片中国 | 亚洲日本在线免费观看 | 精品播放 | 精品久久久久久亚洲 | 黑人特黄aa毛片 | 欧美日本俄罗斯一级毛片 | 国产乱码精品一区二区三区四川 | 成人短视频在线在线观看 |