/**
 * @author: lpy
 * @Date: 2022/11/23
 */
@ComponentScan(basePackages = {"com.cc"})  // 扫扩展包  用于类或接口上主要是指定扫描路径,spring会把指定路径下带有指定注解的类注册到IOC容器中。会被自动装配的注解包括@Controller、@Service、@Component、@Repository等等。
@MapperScan("com.xiaosheng.dao.mapper")
@EnableTransactionManagement(proxyTargetClass = true)
@SpringBootApplication(exclude = {DruidDataSourceAutoConfigure.class})
public class XsVisitorApiApplication {
    public static void main(String[] args) {
        SpringApplication.run(XsVisitorApiApplication.class, args);
    }
}

启动类如上所示,我发现访问controller层写好的接口,直接报404

{
    "timestamp": "2022-11-24T01:58:28.520+00:00",
    "status": 404,
    "error": "Not Found",
    "message": "",
    "path": "/heart"
}

控制台输出

[http-nio-8082-exec-1] com.cf.support.filter.TraceFilter : [1197B6639DD04C148908C1BE9DE54654] Request请求: method = GET; uri = /heart; payload = 
2022-11-24 11:13:34.036 DEBUG --- [http-nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : [1197B6639DD04C148908C1BE9DE54654] GET "/heart", parameters={}
2022-11-24 11:13:34.037 DEBUG --- [http-nio-8082-exec-1] s.d.s.w.PropertySourcedRequestMappingHandlerMapping : [1197B6639DD04C148908C1BE9DE54654] looking up handler for path: /heart
2022-11-24 11:13:34.054 DEBUG --- [http-nio-8082-exec-1] o.s.w.s.h.SimpleUrlHandlerMapping : [1197B6639DD04C148908C1BE9DE54654] Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2022-11-24 11:13:34.057 DEBUG --- [http-nio-8082-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : [1197B6639DD04C148908C1BE9DE54654] Resource not found
2022-11-24 11:13:34.057 DEBUG --- [http-nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : [1197B6639DD04C148908C1BE9DE54654] Completed 404 NOT_FOUND
2022-11-24 11:13:34.060 INFO  --- [http-nio-8082-exec-1] com.cf.support.filter.TraceFilter : [1197B6639DD04C148908C1BE9DE54654] Response响应: ; payload = 

我一看是加载的静态资源,一定是不对的呀,明明加的@RestController

解决

我问了一下,应该是componentScan的问题,有没有扫描到包啊,
我在加本地包之后,
加了注解

@ComponentScan(basePackages = {"com.cc", "com.xiaosheng"})

后发现报错是无法找到bean

2022-11-24 11:58:27.681 DEBUG --- [main] o.s.b.d.LoggingFailureAnalysisReporter : [] Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xiaosheng.facade.facade.AdminReserveFacade' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1714)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1270)

然后看了一下AdminReserveFacadeImpl果真没有加service注解

在加了@Service注解之后,就不报错了,也能找到bean了,apifox调用接口发现也可以调通了

分类: java随笔

0 条评论

发表评论

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注

站点统计

  • 文章总数:304 篇
  • 分类总数:19 个
  • 标签总数:189 个
  • 运行天数:852 天
  • 访问总数:460571 人次
ICP备案号: 辽ICP备20003309号