I am struggling to understand how request scope beans work.
I'm using camel 3.8.0 with javaconfig.
I've made a simple test with rest component, here is the snippet:
------ bean -------
@Component
public class TestBean {
private String param = "";
public TestBean() {
}
public String getParam() {
return param;
}
public void init(@Body ParametriTestScope body) {
System.out.println("initial value " + param);
System.out.println("changing state to " + body.getParam());
param = body.getParam();
}
}
------ bean spring configuration -------
@Configuration
public class TestBeanService {
private TestBean test = new TestBean();
@Bean("testBean")
public TestBean getTest() {
return test;
}
}
and finally the route under test
@Component
public class RottaTestScope extends RouteBuilder {
@Override
public void configure() {
rest("/testscope").post().type(ParametriTestScope.class)
.to("direct:process_testscope");
from("direct:process_testscope")
.to("bean:testBean?scope=Request")
.setBody(simple("${bean:testBean?method=getParam&scope=Request}"));
}
}
I expect this behavior by calling the end point "
http://localhost:8080/testscope"
First postman call should log:
initial value
changing state to hello
Second postman call should log:
initial value
changing state to hello
On the second postman call it logs instead
initial value hello
changing state to hello
which makes me believe that the bean is cached (default scope).
What am I missing?
--
Roberto Gasdia
Software Developer
Innoteam - Digital Change
Innoteam Srl - Via B. Bedosti, 21 - 61122 Pesaro
Phone +39 02 4507 4709 - www.innoteam.it