Can't I @Autowire a Bean which is present in a dependent Library Jar?

后端 未结 1 1381
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 04:27

I have a Spring Boot application (Y) which relies upon a set of Library files packed as x.jar and mentioned as a dependency in the pom.xml of the application Y.

x.ja

1条回答
  •  孤城傲影
    2020-12-31 05:05

    You would need to add the package names of your main class and the User class to be 100% sure, but more then likely, the User class is not in the same package (or a subpackage) of your main class. This means that component scanning will not pick it up.

    You can force spring to look at other packages like this:

    @ComponentScan(basePackages = {"org.example.main", "package.of.user.class"})
    

    0 讨论(0)
提交回复
热议问题