Не удалось autoire bean tomcat IntelliJ - PullRequest
0 голосов
/ 17 апреля 2020

Я столкнулся с большой проблемой в моем приложении. Я создал класс, который использует службу, я думаю, что код в порядке и аннотации тоже. Но когда я запускаю свой tomcat, всплывающее окно «не удалось автоматически передать компонент» моего сервиса и мой tomcat не запускается.

У моего сервиса есть аннотация @Service, он имеет интерфейс и реализует его. Я не знаю, что теперь делать, помогите!

Мой контроллер:

package com.oxylane.cadplm.sampace.api.controller;

import com.oxylane.cadplm.sampace.api.utils.AbstractAuthorizationController;
import com.oxylane.cadplm.sampace.api.utils.Constants;
import com.oxylane.cadplm.sampace.dto.sam.SamManufacturingDto;
import com.oxylane.cadplm.sampace.services.IManufacturingService;
import com.oxylane.cadplm.sampace.utils.api.exception.BusinessException;
import io.jsonwebtoken.JwtException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/v1/manufacturing_time/")
public class ManufacturingController extends AbstractAuthorizationController {

    private static final Logger LOGGER = Logger.getLogger(ManufacturingController.class);

    @Autowired
    IManufacturingService manufacturingService; // the problem is here

Мой сервисный интерфейс:

package com.decathlon.conception.apipace.manufacturingtime.service;

import com.decathlon.conception.apipace.manufacturingtime.dto.SamManufacturingDto;
import com.decathlon.conception.apipace.utils.exception.BusinessException;

import java.util.List;

public interface IManufacturingService {

Мой сервис:

package com.decathlon.conception.apipace.manufacturingtime.service.impl;

import com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao;
import com.decathlon.conception.apipace.manufacturingtime.dao.ISamSectionDao;
import com.decathlon.conception.apipace.manufacturingtime.dao.ISotDao;
import com.decathlon.conception.apipace.manufacturingtime.domain.GenericSam;
import com.decathlon.conception.apipace.manufacturingtime.domain.Sam;
import com.decathlon.conception.apipace.manufacturingtime.domain.Sot;
import com.decathlon.conception.apipace.manufacturingtime.dto.ManufacturingInfosResultDto;
import com.decathlon.conception.apipace.manufacturingtime.dto.PerimeterLightDto;
import com.decathlon.conception.apipace.manufacturingtime.dto.SamManufacturingDto;
import com.decathlon.conception.apipace.manufacturingtime.dto.SamSectionDto;
import com.decathlon.conception.apipace.manufacturingtime.dto.TypeOperationDto;
import com.decathlon.conception.apipace.manufacturingtime.service.IGenericSamService;
import com.decathlon.conception.apipace.manufacturingtime.service.IManufacturingService;
import com.decathlon.conception.apipace.manufacturingtime.service.IShapesClientService;
import com.decathlon.conception.apipace.utils.exception.BusinessException;
import com.decathlon.conception.apipace.utils.transactional.SampaceTransactional;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

@Service
@SampaceTransactional
public class ManufacturingServiceImpl implements IManufacturingService {

Журнал ошибок при запуске tomcat:

17 avr. 2020 08:34:15,339 WARN  org.springframework.web.context.support.XmlWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manufacturingControllerV2': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.service.IManufacturingService com.decathlon.conception.apipace.controller.manifacturingtime.ManufacturingControllerV2.manufacturingService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manufacturingServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao com.decathlon.conception.apipace.manufacturingtime.service.impl.ManufacturingServiceImpl.samDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao] 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)}
17 avr. 2020 08:34:15,341 ERROR org.springframework.web.servlet.DispatcherServlet : Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manufacturingControllerV2': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.service.IManufacturingService com.decathlon.conception.apipace.controller.manifacturingtime.ManufacturingControllerV2.manufacturingService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manufacturingServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao com.decathlon.conception.apipace.manufacturingtime.service.impl.ManufacturingServiceImpl.samDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao] 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)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1218)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:778)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:666)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:632)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:680)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:551)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:492)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4871)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5180)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1728)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.service.IManufacturingService com.decathlon.conception.apipace.controller.manifacturingtime.ManufacturingControllerV2.manufacturingService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manufacturingServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao com.decathlon.conception.apipace.manufacturingtime.service.impl.ManufacturingServiceImpl.samDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao] 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$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 67 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manufacturingServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao com.decathlon.conception.apipace.manufacturingtime.service.impl.ManufacturingServiceImpl.samDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao] 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)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1218)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
[2020-04-17 08:34:15,417] Artifact apipace-server-mvc:war exploded: Artifact is deployed successfully
[2020-04-17 08:34:15,417] Artifact apipace-server-mvc:war exploded: Deploy took 330,451 milliseconds
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1021)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 69 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao com.decathlon.conception.apipace.manufacturingtime.service.impl.ManufacturingServiceImpl.samDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao] 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$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 80 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao] 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.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1380)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1021)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 82 more

Спасибо за помощь!

1 Ответ

0 голосов
/ 21 апреля 2020

В вашем исключении упоминается, что реальная проблема заключается в том, что com.decathlon.conception.apipace.manufacturingtime.dao.ISamDao не может быть подключен автоматически.

Скорее всего, ISamDao (или подкласс) не имеет @ Component / @ Service или @Repository

...