注入错误了
老师你好,请问这个问题怎么解决呢,我把业务层从SSM迁移过来就出现这个问题了,
这个要成功注入我的理解是mapper.xml里面的namespace要指向dao接口,然后mapperscan扫描实现注入,不知道我理解的对不对
之前我测试areadao的时候都是可以正常测试的
一样的问题
41
收起
正在回答 回答被采纳积分+1
8回答
不停奔跑的小恐龙
2020-03-11 21:23:55
package com.imooc.o2ov2.Config.dao; import org.mybatis.spring.SqlSessionFactoryBean; import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.core.io.support.ResourcePatternResolver; import javax.annotation.Resource; import javax.sql.DataSource; import java.io.IOException; @Configuration public class SessionFactoryConfiguration { @Resource private DataSource dataSource; private String typeAliasesPackage = "com.imooc.o2ov2.entity"; private String mapperLocations = "/mapper/**.xml"; private String configLocation = "mybatis-config.xml"; @Bean(name="sqlSessionFactory") public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(configLocation)); PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver(); String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperLocations; sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath)); sqlSessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage); sqlSessionFactoryBean.setDataSource(dataSource); return sqlSessionFactoryBean; } }
老师你好我都配置在这里面了,没有像老师那样设置成静态属性,麻烦老师看看这样写着有错吗
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星