色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

瀏覽:142日期: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
主站蜘蛛池模板: 99久久精品毛片免费播放 | 老色99久久九九精品尤物 | 欧洲成人免费视频 | 亚洲精品中文一区不卡 | 免费日韩一级片 | 亚州综合网 | 日本爽快片100色毛片 | 91久久精品青青草原伊人 | 欧美日韩一区二区三区视视频 | 国产欧美日韩在线观看 | 521a久久九九久久精品 | 太平公主三级dvd | 国内自拍在线观看 | 国产精品久久久久9999小说 | 欧美日韩精品一区二区三区视频在线 | 欧美成人精品高清在线播放 | 亚洲视频三级 | 久久精品国产欧美成人 | 91在线亚洲| 成 人 黄 色 激 情视频网站 | a亚洲天堂 | 日本成aⅴ人片日本伦 | 伊人久久国产免费观看视频 | 久草在线视频精品 | 欧美在线成人免费国产 | 日本亚洲免费 | 看片日韩| 国产美女在线一区二区三区 | 日本三级成人中文字幕乱码 | 欧美 自拍 丝袜 亚洲 | 精品久久久久久无码中文字幕 | 亚洲精品国产成人一区二区 | 1级a的观看视频 | 久久免费视频1 | 欧美在线一级毛片视频 | 免费一级毛片麻豆精品 | 久久精品免视看国产明星 | 91精品久久久久久久久久 | 日韩一区二区三区在线 | 久久这里一区二区精品 | 香港三级日本三级妇人三级 |