简体   繁体   中英

error - a bean of type 'package' while injecting dependency of one service into another services controller[Spring-Boot]

I have a jar library where one service declaration looks like this

@org.springframework.stereotype.Service
public class ABC {

Now I have imported this jar file using maven pom.xml in different service and where my code looks like this

    import a.b.ABC


    @RestController
    @RequestMapping("")
    @Slf4j
    public class xyz {
    @Autowired
    private ABC abcd;

When compiling with mvn clean install, this is the error, I am getting

{"json_mssg": {"date": "21-07-2021 20:29:06.653", "thread": "main", "level": "ERROR", "log": " newline____newlinenewline__APPLICATION FAILED TO START__newline __newline____newline__Description:__newline____newline__Field abcd in xyzxxController required a bean of type 'abABC' that could not be found.__newline____newline__The injection point has the following annotations: newline - @org.springframework.beans.factory.annotation.Autowired(required=true)__newline____newline____newline__Action:__newline____newline__Consider defining a bean of type 'glance.content.server.beacon.BeaconFactory' in your configuration. newline ", "logger": "org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter", "method": "report", "ex": ""}}

How can I initialise the object or how can I use the object of ABC here ?? I am very new to spring and java.

在您的 SpringBootApplication 类上使用 @Import(ABC.class) 或在您初始化和配置 ABC 类的地方创建 bean (@Configuration+@Bean)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM