The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

475074 (5) [Avatar] Offline
#1
David,
Many thanks for your suggestion and help in advance.

I know that you guys did not use @Inject annotation in none of your example.
But I was trying to use it and there was no success, the value was not injected.
I am working with Mule 3.3.2

Based on documentation:
"
JSR 330's @Inject annotation can be used in place of Spring's @Autowired
".

However, when I used @Autowired all worked, Beans were properly scanned and loaded. ( I used
@Component 
for each bean
and
<context:component-scan base-package="com.xxx, com.yyy"/>


I am not sure if I need it but I do have in my mule-deploy .proeprties file
scan.packages=com.xxx, com.yyy 

in addition to
context:component-scan



This is the Bean B where I have attempted to use @Inject

package com.xxx;

@Component(value="componentC")
public class C {
	
	private final Logger log; 
	
	public UpdateService updateService;
	
	@Inject
	private B beanB;
	 
	public C() {
		log = LoggerFactory.getLogger(getClass());
	}
	
	/**
	 * this method will be invoked from another bean using binding interface technique
	 * @param message
	 */
	public void invoke(MessageXYZ message) {
		beanB.sayHello("Mule");
	}
	
	public UpdateService getUpdateService() {
		return updateService;
	}

	public void setUpdateService(UpdateService updateService) {
		this.updateService = updateService;
	}
}


This is B bean which is invoking C Bean

package com.xxx;

@Component (value="componentB")
public class B  {
	
	private final Logger log;
	
	public UpdateService updateService;
	
	public B() {
		log = LoggerFactory.getLogger(getClass());
	}
	
	/**
	 * this method will be invoked from Bean X
	 * @param message
	 */;
	public MessageXYZ invoke(MessageXYZ message) {
		
		updateService.analyze(message);
		return message;
	}

	public void sayHello(String name) {
		log.info("Hello from " + name);
	}
	public UpdateService getUpdateService() {
		return updateService;
	}

	public void setUpdateService(UpdateService updateService) {
		this.updateService = updateService;
	}



I have 2 config files
This is snapshot of 1st one

<spring:beans>
		<spring:import resource="spring-beans.xml" />
	</spring:beans>        

     <flow name="flowB">
   		<vm:inbound-endpoint path="agency.service.b" exchange-pattern="request-response"/>
   		<component doc:name="component B">
   			<spring-object bean="componentB" />
   			
   			<binding interface="com.home.UpdateService" method="analyze">
           		    <vm:outbound-endpoint path="agency.service.c" exchange-pattern="request-response"/>
                        </binding>
   		</component>
   		<exception-strategy ref="CatchExceptionStrategy" doc:name="Reference Exception Strategy" />
   	</flow>
   	
   	<flow name="flowC">
   		<vm:inbound-endpoint path="agency.service.c" exchange-pattern="request-response"/>
   		<component doc:name="component C">
   			<spring-object bean="componentC" />
   		</component>
   		<vm:outbound-endpoint path="agency.service.a"/>
   		<exception-strategy ref="CatchExceptionStrategy" doc:name="Reference Exception Strategy" />
   	</flow>


And this is second one that is referenced by 1st one

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/context
	   		http://www.springframework.org/schema/context/spring-context.xsd
	   		http://www.springframework.org/schema/beans
			http://www.springframework.org/schema/beans/spring-beans.xsd">

	
	<context:component-scan base-package="com.xxx, com.yyy"/>
</beans>
David Dossot (233) [Avatar] Offline
#2
I'm unsure why it doesn't work. Maybe Mule doesn't support the mix of Spring / JSR-330 annotations you're using? Have you tried using
@Named
instead of
@Component
?

In any case, this is a question that would better be on Stack Overflow or the MuleSoft forums.
475074 (5) [Avatar] Offline
#3
David, thank you for your reply.
I did try your suggestion to use @Named instead of @Component, but as I was starting local Mule server in Eclipse I got error that
the bean with @Named was not loaded.

I know this question is not related directly to the book, Thank you again
Boris