报错信息长这样子,又臭又长,英文一塌糊塌的我只认出了那个自己写的”helloService”和经常见过的“could not be found”
Description:
A component required a bean of type 'cn.hello.service.HelloService' that could not be found.
Action:
Consider defining a bean of type 'cn.hello.service.HelloService' in your configuration.
2020-06-22 11:28:22.635 WARN 6372 --- [ main] o.s.boot.SpringApplication : Unable to close ApplicationContext
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
找不到?莫非少了注解~那先瞅瞅那个叫做“Helloservice"的东东
public interface HelloService {
int insert(List<Hello> list);
int del(int[] ids);
}
两个方法,没毛病,那么简介简单简陋~再瞅瞅它的实现类:
@Service
public class HelloServiceImpl{
@Resource
private HelloMapper helloMapper;
public int insert(List<Hello> list){
return this.helloMapper.insert(list);
}
public int del(int[] ids){
return this.helloMapper.del(ids);
}
}
细心的小哥眼睛这么一瞥就发现原来没写”implements HelloService“,加上去在运行就正常了
@Service
public class HelloServiceImpl implements HelloService {
@Resource
private HelloMapper helloMapper;
public int insert(List<Hello> list){
return this.helloMapper.insert(list);
}
public int del(int[] ids){
return this.helloMapper.del(ids);
}
}
这个是我批量插入和批量删除的方法,一开始没写接口,直接写了个类调用一下mapper里面的方法,一帆风顺~后来我想着有个接口可能看着更高大上一点,没想弄巧成拙。作为一个代码的搬运工,一开始我就应该创建接口,接着写实现类,一步一jio印,将一行一行的代码稳妥的放置在合理的位置。它好我也好,hhh------以后再细心些吧!
<------------希望我入过的歧途,能对你有帮助----------->