You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ron Cecchini <ro...@comcast.net> on 2018/10/11 22:49:30 UTC

Timing problem of Spring Injection vs. Component Scan?

Hi, all.

I have a Camel/Spring Boot app created from the camel-spring-boot archetype.

I've set up my several Processor and RouteBuilder classes with @Component and have essentially avoided resources/spring/camel-context.xml.

I'm now trying to incorporate a new class which has its own Spring configuration file associated with it ("default-configuration.xml").

I've tried auto-wiring a bean defined in 'default-configuration.xml' into a variable defined in one of my @Component classes - but I keep getting that the bean isn't defined.  (something like, "no suitable bean of type <type> found for auto-wire" -- even though I clearly have such a bean in my Spring config.)

I tried @Autowired on both the variable and then on a setter method.  Both fail.

I assumed this is because the Component scan is being done before the Spring injection...?

Or maybe that doesn't even make sense...

I've googled and searched to see if Spring Boot is looking for Spring configs of a certain name or in a certain location ...?  Or if I have to list the configs in CamelContext in camel-context.xml ...?

At this point I'm throwing things at the wall and seeing what will stick ...

HUGE THANK YOUS as always for your help.

Re: Timing problem of Spring Injection vs. Component Scan?

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Ron,
Spring dependency injection works by (first) scanning all potential
sources of beans to inject and then (second) instantiating singletons
and injecting them as needed. Thus it's very unlikely that it fails to
resolve a dependency to inject if that dependency is known to Spring,
this can only happen in very complex hierarchies of application
contexts.

Most likely you're having issue loading or instantiating the new
configuration. I would suggest that you start by moving the bean you
defined in this new configuration file to a pre-existing configuration
file or @Configuration class to determine if the new configuration
file is being scanned at all.

zoran

On Fri, Oct 12, 2018 at 12:49 AM, Ron Cecchini <ro...@comcast.net> wrote:
> Hi, all.
>
> I have a Camel/Spring Boot app created from the camel-spring-boot archetype.
>
> I've set up my several Processor and RouteBuilder classes with @Component and have essentially avoided resources/spring/camel-context.xml.
>
> I'm now trying to incorporate a new class which has its own Spring configuration file associated with it ("default-configuration.xml").
>
> I've tried auto-wiring a bean defined in 'default-configuration.xml' into a variable defined in one of my @Component classes - but I keep getting that the bean isn't defined.  (something like, "no suitable bean of type <type> found for auto-wire" -- even though I clearly have such a bean in my Spring config.)
>
> I tried @Autowired on both the variable and then on a setter method.  Both fail.
>
> I assumed this is because the Component scan is being done before the Spring injection...?
>
> Or maybe that doesn't even make sense...
>
> I've googled and searched to see if Spring Boot is looking for Spring configs of a certain name or in a certain location ...?  Or if I have to list the configs in CamelContext in camel-context.xml ...?
>
> At this point I'm throwing things at the wall and seeing what will stick ...
>
> HUGE THANK YOUS as always for your help.



-- 
Zoran Regvart