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

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

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

瀏覽:124日期: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精品国产在热久久 | www四虎com| 国产亚洲一区二区三区在线观看 | 国产欧美精品一区二区三区 | 国产精品视频不卡 | 亚洲国产中文字幕 | 亚洲免费精品一区 | 久久久久国产一区二区三区 | 亚洲人在线 | 成人午夜精品 | av在线一区二区三区 | 国产精品久久久久久 | 日韩在线免费视频 | 欧美精品中文字幕久久二区 | 99热精品久久 | 久久久久久国产 | 色婷婷久久 | 国产一区二区三区免费 | 午夜精品一区二区三区在线 | 久久久久久高潮国产精品视 | 91精品欧美久久久久久久 | 日本在线视频中文字幕 | 精品真实国产乱文在线 | 欧美大片在线观看 | 自拍视频精品 | 四虎精品在线 | 中文字幕一区在线 | 日韩在线免费视频 | 日韩欧美在线视频观看 | 一级黄色短片 | 麻豆精品久久久 | 99免费精品视频 | 天天操天天摸天天爽 | 国产乱码精品一品二品 | 亚洲福利在线视频 | 黄片毛片在线观看 | 亚洲欧美一区二区三区在线 | 精品综合久久 | 久久久久久亚洲精品 | 日韩h| 欧美一区二区三区精品 |