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

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

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

瀏覽:100日期: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级网站 | 亚洲综合色就色手机在线观看 | 国产精品自在线天天看片 | 国产精品久久久久久久久久久不卡 | 播放一级毛片 | 亚洲成人手机在线观看 | 成人免费一级在线播放 | 欧美激情综合亚洲一二区 | 欧美日本一区视频免费 | 无限资源中文免费 | 免费国产成人手机在线观看 | 欧美二区视频 | 美女曰皮 | 中文在线视频观看 | 国产午夜精品久久理论片小说 | 99热精品在线免费观看 | 国产精品视频九九九 | 亚洲日本欧美综合在线一 | 欧美一级二级三级视频 | 欧美日韩在线视频不卡一区二区三区 | 全部aⅴ极品视觉盛宴精品 全部免费a级毛片 | 国内国语一级毛片在线视频 | 国内国外精品一区二区 | 国产亚洲综合久久 | 亚洲日本在线看片 | 美女黄18 | 久久免费视频在线 | 午夜不卡在线 | 久久久夜间小视频 | 亚洲国产精品久久综合 | 精品极品三级久久久久 | 国产一级毛片外aaaa | 亚洲视频在线观看网址 | 亚洲美女色成人综合 | 大学生一级一片第一次免费 | 美女黄频免费看 | 日韩欧美一级毛片在线 | 日韩欧美一及在线播放 | 亚洲视频中文 |