先把问题贴出来: @org.springframework.beans.factory.annotation.Autowired(required=true) 报这个错是因为: @Autowired(required=true):当使用@A
先把问题贴出来:
@org.springframework.beans.factory.annotation.Autowired(required=true)
报这个错是因为:
@Autowired(required=true):当使用@Autowired注解的时候,其实默认就是@Autowired(required=true),表示注入的时候,该bean必须存在,否则就会注入失败。
package com.yyyy.eamon.dao;import tk.mybatis.mapper.common.Mapper;import com.yzym.eamon.domain.CommUnity;//import org.springframework.stereotype.Repository;//import com.yzym.eamon.service.impl.CommunityServiceImpl;//import org.springframework.context.annotation.Bean;//import org.springframework.context.annotation.Configuration;//////@Configuration //自动注入,程序一开始就注册实例public interface CommunityMapper extends Mapper {}
**
**
package com.yzym.eamon.service.impl;import com.yzym.eamon.dao.CommunityMapper;import com.yzym.eamon.domain.Community;import com.yzym.eamon.service.CommunityService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.ArrayList;import java.util.List;//import org.springframework.context.annotation.Bean;//import org.springframework.context.annotation.Configuration;////@Configuration //自动注入,程序一开始就注册实例@Servicepublic class CommunityServiceImpl implements CommunityService { @Autowired private CommunityMapper communityMapper; @Override public List findAll(){ List communities = communityMapper.selectAll(); return communities; }}
package com.yzym.eamon;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import tk.mybatis.spring.annotation.MapperScan;//@SpringBootApplication//MapperScan要导入Tk包//@MapperScan(basePackages = {"com.yzym.eamon.dao "})@MapperScan(basePackages = "#####") //这里填自己的地址参考Mapper的package包的位置@SpringBootApplicationpublic class EamonApplication { public static void main(String[] args) { SpringApplication.run(EamonApplication.class, args); }}
解决办法:
1、先看sevice层,你有没有加上@Service注解。2、再看mapper层有没有加上@Mapper注解,以及在启动类上有没有加上@MapperScan来扫描mapepr
来源地址:https://blog.csdn.net/MiRemember/article/details/128055313
--结束END--
本文标题: 解决报错:@org.springframework.beans.factory.annotation.Autowired(required=true)
本文链接: https://lsjlt.com/news/371616.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-04-01
2024-04-03
2024-04-03
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0