国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:137日期: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
主站蜘蛛池模板: 亚洲精品国产男人的天堂 | 免看一级a毛片一片成人不卡 | 国产在线啪| 怡红院宜春院 | 国产成人aaa在线视频免费观看 | 一级做a爱过程免费观看 | 久久精品免视着国产成人 | 国产一区二区在免费观看 | 亚洲视频免费在线 | 在线亚州| 久久久精品久久久久三级 | 久久国产亚洲欧美日韩精品 | 日韩一区二区在线免费观看 | 久久久久毛片成人精品 | 欧美同性videos在线可播放 | 欧美一级在线毛片免费观看 | 手机在线黄色网址 | 一级做a爱久久久久久久 | 日本在线加勒比 | 美国一级大黄香蕉片 | 日韩在线1 | 国产伦精一区二区三区视频 | 日本香蕉一区二区三区 | 欧美国产三级 | 精品欧美高清不卡在线 | 久久精品最新免费国产成人 | 久久国产精品一国产精品 | 性理论片 | 成人国产精品免费网站 | 亚洲综合伊人色一区 | 在线亚洲一区二区 | 精品国产福利 | 国模偷拍在线观看免费视频 | 中文字幕一区视频一线 | 毛片视频在线免费观看 | 日韩一区二区三区视频在线观看 | 一级片aaa| 欧美三级日韩 | 亚洲精品一区二区三区网址 | 久久久久国产视频 | av毛片免费看 |