Re: Camel-boot autowiring issue

2015-01-06 Thread Steven Marcus
Hello,

Thanks for the sample project. I adapted it to experiment with
@EndpointInject and @Produces -- they appear to be broken with spring-boot?

The shouldInjectCamelContext() test fails with null for resultEndpoint --
and template is null too.
(Using recently updated camel-spring-boot SNAPSHOT.)

@BootstrapWith(CamelTestContextBootstrapper.class)
@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringApplicationConfiguration(classes = {CamelConfigurationTest.class,
MyCamelConfiguration.class})
@RunWith(CamelSpringJUnit4ClassRunner.class)
public class CamelConfigurationTest extends Assert {

@Autowired
CamelContext camelContext;

@Value(${name})
String name;
@Autowired
private CamelConfigurationProperties configurationProperties;
@Autowired
private Environment env;

@EndpointInject(uri = mock:result)
private MockEndpoint resultEndpoint;

@Produce(uri = direct:RoomSyncRouteTest)
private ProducerTemplate template;

@Test
public void shouldInjectCamelContext() {
assertNotNull(camelContext, camelContext);
assertNotNull(configurationProperties, configurationProperties);
assertNotNull(env, env);
assertNotNull(name, name);
assertNotNull(resultEndpoint, resultEndpoint);
assertNotNull(template, template);
}

@Test
public void shouldLoadRoute() {
assertEquals(1, camelContext.getRoutes().size());
}
}

Camel + spring boot looks like a great combo...

TIA!
Steven




--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-boot-autowiring-issue-tp5758543p5761414.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel-boot autowiring issue

2014-11-07 Thread vasilievip
Ok, I tested out the change and it works like a charm in unit test, but in
main class itself I think there is still some issue. 

Lets take as an example Boot1.java from my example project, if I do this:

@Configuration
@EnableAutoConfiguration
@Import({*CamelAutoConfiguration.class,* CamelConfiguration.class})
public class Boot1 {

@Value(${name})
String name;

public static void main(String[] args) {
SpringApplication.run(Boot1.class, args);
}

@Bean(name = someProperty)
public String getPropertyValue() {
return name;
}
}

It works well, but if I remove CamelAutoConfiguration.class from imports,
then the issue is still the same (I guess CamelAutoConfiguration is
processed *after* my routes config). 






--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-boot-autowiring-issue-tp5758543p5758667.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel-boot autowiring issue

2014-11-07 Thread vasilievip
Oops, my bad,  the issue is that spring-boot-autoconfigure dependency is only
available for test scope 




--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-boot-autowiring-issue-tp5758543p5758668.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel-boot autowiring issue

2014-11-07 Thread Henryk Konsek
 Oops, my bad,  the issue is that spring-boot-autoconfigure dependency is only
 available for test scope

Everything's OK then? :)

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com


Re: Camel-boot autowiring issue

2014-11-07 Thread vasilievip
Yes, everything works fine. Thank you!
Looks like for the main, optional flag makes some classpath magic not
working :)
dependency
groupIdorg.springframework.boot/groupId
artifactIdspring-boot-starter/artifactId
version${spring-boot.version}/version
*optionaltrue/optional*




--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-boot-autowiring-issue-tp5758543p5758675.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel-boot autowiring issue

2014-11-07 Thread Henryk Konsek
 Looks like for the main, optional flag makes some classpath magic not
 working :)
 dependency
 groupIdorg.springframework.boot/groupId
 artifactIdspring-boot-starter/artifactId
 version${spring-boot.version}/version
 *optionaltrue/optional*

Have you got any concrete example demonstrating this issue? I'd like
to keep this dependency optional, as it should be up to the developer
to pick the Spring Boot version of his/her choice.

Cheers.

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com


Re: Camel-boot autowiring issue

2014-11-07 Thread vasilievip
See attached:
camel-spring-boot-example.zip
http://camel.465427.n5.nabble.com/file/n5758700/camel-spring-boot-example.zip 
 

- Run Boot1 and take a look at output
- Run Boot2 and take a look at output



--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-boot-autowiring-issue-tp5758543p5758700.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel-boot autowiring issue

2014-11-06 Thread Henryk Konsek
Hi,

 OK, I can see possible improvement for camel-spring-boot, as well as
 small misconfiguration in your project. I'll send more details later
 today. Stay tuned :)

I tuned the camel-spring-boot code to postpone the moment of injecting
routes until all beans are initialized. This will help to deal with
the situations when you inject CamelContext into the configuration
creating RoutesBuilder. To be honest this kind of injection
(CamelContext into the RoutesBuilder or its config file) is rather the
anti-pattern IMHO as routes builders shouldn't be aware of  the
CamelContext, but after my improvement it is possible.

All you need to change in your example now is to swap config files order:

@SpringApplicationConfiguration(classes =
{CamelConfigurationTest.class, CamelConfiguration.class})
... instead of ...
@SpringApplicationConfiguration(classes = {CamelConfiguration.class,
CamelConfigurationTest.class})

You need to load test config before the regular configuration. This is
general rule for Spring Java configurations.

Let me know if it works for you with new snapshot and swapped configs.
Works like a charm on my machine [1] :) . Ping me in case of any
additional problems.

Cheers.

PS Give a moment for our CI server to deploy new snapshots or build it
locally from the master branch.

[1] http://sd.keepcalm-o-matic.co.uk/i/keep-calm-it-works-on-my-machine-8.png

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com


Re: Camel-boot autowiring issue

2014-11-06 Thread vasilievip
Thanks! 
Will try latest changes and let you know the results.



--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-boot-autowiring-issue-tp5758543p5758592.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel-boot autowiring issue

2014-11-05 Thread Henryk Konsek
Hi,

 Here is sample project I prepared to demonstrate the issue:

I will take a look it shortly. Thanks for reporting :) .

Cheers.

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com


Re: Camel-boot autowiring issue

2014-11-05 Thread Henryk Konsek
OK, I can see possible improvement for camel-spring-boot, as well as
small misconfiguration in your project. I'll send more details later
today. Stay tuned :)


Cheers.

On Wed, Nov 5, 2014 at 3:53 PM, Henryk Konsek hekon...@gmail.com wrote:
 Hi,

 Here is sample project I prepared to demonstrate the issue:

 I will take a look it shortly. Thanks for reporting :) .

 Cheers.

 --
 Henryk Konsek
 http://henryk-konsek.blogspot.com



-- 
Henryk Konsek
http://henryk-konsek.blogspot.com