Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

None or multiple beans found in Spring context for type class ...myPackageHere..., skipping the type

My Jersey Java classes looks like this:

@Component
...class...MyComponent...extends myParent

And in the parent class:

...abstract class myParent...

  @Autowired
  SomeBean myAutowiredBean

I get some strange warnings when my server starts about:

Nov 14, 2014 10:41:23 AM org.glassfish.jersey.server.spring.SpringComponentProvider bind SEVERE: None or multiple beans found in Spring context for type class ...myPackageAndClassHere..., skipping the type.

Despite the warning message everything works as intended. Every class extending the parent has this warning. Has this to do with the abstract nature of the parent class ?

I found this page where someone else has a similar issue, is this a jersey/spring problem ? I use Jersey 2.11 and Spring 3.2.3.

like image 621
Christophe Roussy Avatar asked Nov 14 '14 10:11

Christophe Roussy


1 Answers

I faced the same problem. My REST resources responded correctly, but I got the same SEVERE Message. Actually, if trying to inject some of my beans into some of the REST service, I got NullPointerException on any bean injected call.

What happened is that jersey initialized the rest services but did not initialize my spring beans (Let me say...correctly, I had to!!)

I solved just making spring aware of my bean :)

Just add context:component-scan base-package="myPackage"

The warning (and NullPointers) disappeared!

like image 144
di.elle Avatar answered Oct 30 '22 09:10

di.elle