Tag Archives: bean

mule with spring-beans and autowire…

… doesnt work 🙁

i really think (now partly thought) spring is cool… i used a spring-bean configfile, initialised all the entities and @Autowired them.. pretty cool… reflection on the entities to find and load them… and i think its really readable in java code… whenever you see an @Autowired… it will be created someware completely different and reflected to the position…

but autowiring with mule dont work… or i couldnt figure out how… mule runs its own context and the springcontext is somewhere in there… and the springcontext behaves different… crap… so new solution:

beans.xml

<bean id=”A” class=”ch.michio.spring.A”/>

<bean id=”B” class=”ch.michio.spring.B”>
     <property name=”a” ref=”A”/>
</bean>

so in class B there was an:

@Autowired
private A a;

 now there is a setter:

private A a;
public setA(A a){
     this.a = a;
}

So during initialisation

  1. an A object is created
  2. a B object is created
  3. a in spring bean container found A is set to B

my main problem with this solution is the readability… you need to read the java files AND the beans.xml… bah… 🙁

mule with spring and testing without mule…

mule is able to import spring beans… as expected 🙂 but to test those… its kinda hard… 🙁

first create an own bean config file separated from the mule-config.xml and include it in mule-config.xml with following tags:

<spring:beans>
<spring:import resource=”beans.xml”/>
</spring:beans>

simple 🙂 now the beans.xml is a simple springbeans config file… with <beans> as root tag and <bean>’s inside. easy too…

and now use following annotation in the unittest:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={“classpath:beans.xml”})

this should now load the bean correctly during test…