问答详情
源自:3-3 datasource和sessionfactorybean的配置

@Qualifier注解后的dataSource飘红

package com.imooc.demo.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.activation.DataSource;
import java.io.IOException;

@Configuration
public class SessionFactoryConfiguration {
//    mybatis-config.xml配置文件的路径
   @Value("${mybatis_config_file}")
   private String mybatisConfigFilePath;

//    mybatis mapper文件所在路径
   @Value("${mapper_path}")
   private String mapperPath;

//    实体类所在的package
   @Value("${entity_package}")
   private String entityPackage;

   @Autowired
   @Qualifier("dataSource")//这个地方!!!!!!!
   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((javax.sql.DataSource) dataSource);
       sqlSessionFactoryBean.setTypeAliasesPackage(entityPackage);
       return sqlSessionFactoryBean;
   }
}


提问者:qq_白衣不与时光老_0 2018-05-26 20:49

个回答

  • 慕尼黑星Star
    2018-06-14 11:01:08

    https://img1.mukewang.com/5b21d6260001df1904980135.jpg

    不用理会,你可以在错误检查里面关掉。

  • 慕尼黑星Star
    2018-06-14 10:38:06

    我也是相同问题https://img.mukewang.com/5b21d508000106fd10010477.jpg

  • 慕斯7102584
    2018-06-03 21:36:38

    提示的错误问题是什么啊