java - 没有找到处理方法

标签 java spring-boot spring-restcontroller

我正在尝试调用休息端点,但在调用它时获取此信息,导致 UI 中出现 404 错误

2016-08-07 13:43:42.611 DEBUG 27834 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /api/v1/operations
2016-08-07 13:43:42.614 DEBUG 27834 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/api/v1/operations]
2016-08-07 13:43:42.615 DEBUG 27834 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/api/v1/operations] are [/**]
2016-08-07 13:43:42.616 DEBUG 27834 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/api/v1/operations] are {}
2016-08-07 13:43:42.617 DEBUG 27834 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/api/v1/operations] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@39ead1b7]]] and 1 interceptor

同一包中有 2 个具有不同端点的 Controller 类

@RestController
public class OperationRetrievalController {
    
    @Autowired
    OperationRetrievalManager operationRetrievalManager;
    
    private static Logger logger = Logger.getLogger(OperationRetrievalController.class);
    
    @RequestMapping("/api/v1/operations")
    public ResponseEntity<List<OperationView>> requestUserOperations() {
        String ssoId = "xxxxxx";
        logger.info("Inside request operationRetrivel Manager +++++++++>>>>>>>>");
        return new ResponseEntity<List<OperationView>>(operationRetrievalManager.retrieveOperations(ssoId), HttpStatus.OK);
    }
    
    
}

我在同一个包中有另一个类:

@RestController
public class ComponentRetrievalController {
    
    @Autowired
    ComponentRetrievalManager componentRetrievalManager;
    
    @RequestMapping(value = "api/v1/component/{sso_id}" , method=RequestMethod.GET)
    public ResponseEntity<List<Component>> requestUserComponent(@PathVariable("sso_id") String ssoId) {
        
        return new ResponseEntity<List<Component>>(componentRetrievalManager.retrieveComponents(ssoId), HttpStatus.OK);
    }
}

这是 Spring Boot 应用程序类:

@SpringBootApplication
@EnableAutoConfiguration
@EnableJpaRepositories(basePackages="com.ge.power.bis.repositories")
@ComponentScan(basePackages="com.ge.power.bis.managers")
public class Application {
    
    private static Logger logger = Logger.getLogger(Application.class);


    public static void main(String[] args) {
        
        SpringApplication springApplication = new SpringApplication(Application.class);

        ApplicationContext ctx = springApplication.run(args);

        logger.info("Let's inspect the beans provided by Spring Boot:");
        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames)
        {
            logger.info(beanName);
        }       
    }
}

这是我的包的结构 Package structure

当我删除 Application.java 中的所有注释并仅保留 @SpringBootApplication 时,它会出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'componentRetrievalController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.ge.power.bis.managers.ComponentRetrievalManager com.ge.power.bis.controllers.ComponentRetrievalController.componentRetrievalManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ge.power.bis.managers.ComponentRetrievalManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapable

最佳答案

其中一个 Impl 类缺少 @Service

关于java - 没有找到处理方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38817471/

相关文章:

java - Hadoop MapReduce输出最大

java - 如何识别项目中的测试类

java - 使用 Spring Boot 连接到 MySQL 数据库时遇到问题

java - Spring Rest 模板覆盖 Authorization header 值

java - 是否可以在 Spring Controller 中拆分请求参数?

java - 字符串标记化的问题

java - Hibernate @Size 验证自定义类型

部署到 Springboot 应用程序后,Angular 路由不起作用

java - Spring-返回对象列表的请求方法显示错误

spring - 没有@RequestParam,参数绑定(bind)如何/为什么工作?