亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

@Qualifier("dataSource")報錯!

http://img1.sycdn.imooc.com//5aa778500001a3bc05110154.jpg

我都是跟著視頻敲的 為什么到了這里會出錯呢

正在回答

5 回答

https://img1.sycdn.imooc.com//5b19299400013e6509870363.jpg

你所建的config包必須和Application類同級或更低級,才會被掃描,注意springboot工程結構,問題解決。

0 回復 有任何疑惑可以回復我~

我也出現了這個問題,請問怎么解決


0 回復 有任何疑惑可以回復我~

我也出現了這個錯誤請問樓主解決了嗎

0 回復 有任何疑惑可以回復我~

package config.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.beans.PropertyVetoException;

@Configuration
//配置mybatis中mapper的掃描路徑
@MapperScan("com.imooc.demo.dao")
public class DataSourceConfiguration {
? ?@Value("${jdbc.driver}")
? ?private String jdbcDriver;
? ?@Value("${jdbc.url}")
? ?private String jdbcUrl;
? ?@Value("${jdbc.username}")
? ?private String jdbcUserName;
? ?@Value("${jdbc.password}")
? ?private String jdbcPassword;

? ?@Bean(name="dataSource")
? ?public ComboPooledDataSource createDataSource() throws PropertyVetoException {
? ? ? ?//設置數據源
? ? ? ?ComboPooledDataSource dataSource = new ComboPooledDataSource();
? ? ? ?dataSource.setDriverClass(jdbcDriver);
? ? ? ?dataSource.setJdbcUrl(jdbcUrl);
? ? ? ?dataSource.setUser(jdbcUserName);
? ? ? ?dataSource.setPassword(jdbcPassword);
? ? ? ?//關閉連接后不自動提交
? ? ? ?dataSource.setAutoCommitOnClose(false);
? ? ? ?return dataSource;
? ?}
}

0 回復 有任何疑惑可以回復我~

package config.dao;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;
import java.io.IOException;

//掃描這個類
@Configuration
public class SessionFactoryConfiguration {
? ?@Value("${mybatis_config_file}")
? ?private String myBatisConfigFilePath;
? ?@Value("${mybatis_path}")
? ?private String mapperPath;
? ?@Value("${entity_package}")
? ?private String entityPackage;

? ?@Autowired
? ?private DataSource dataSource;

? ?@Bean(name="sqlSessionFactory")
? ?public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
? ? ? ?SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
? ? ? ?sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(myBatisConfigFilePath));
? ? ? ?PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
? ? ? ?String packageSearchPath = PathMatchingResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPath;
? ? ? ?sqlSessionFactoryBean.setMapperLocations(resolver.getResources(packageSearchPath));
? ? ? ?sqlSessionFactoryBean.setDataSource(dataSource);
? ? ? ?sqlSessionFactoryBean.setTypeAliasesPackage(entityPackage);
? ? ? ?return sqlSessionFactoryBean;
? ?}
}

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

@Qualifier("dataSource")報錯!

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號