views:

354

answers:

3

I am developing a GWT-Spring-Hibernate project and I want to use Spring Autowired annotation in GWT Service Servlet but my autowired annotated service is not injected. it is null. Is there a configuration detail that I missed?

I add

<context:annotation-config />
<context:component-scan base-package="com.org" />

to my ApplicationContext.xml and I have annotated my service as @Service("myService")

@Autowired
MyService myService;  // This is null so WHY?
A: 

Is class you're trying to inject your service into actually a bean declared in Spring context? It should be, auto-wiring won't work otherwise.

It can either be declared explicitly or, provided that it's somewhere within your "com.org" hierrarchy it will be detected automatically IF it's annotated as @Component or one of other stereotypes provided by Spring.

ChssPly76
Package for MyService is com.org and annotation by @Service stereotypes so I think it is enough to inject
Firstthumb
I wasn't asking about MyService. A quote from above: "class you're trying to **inject** your service **into** ".
ChssPly76
I calling MyService in GWT Servlet so you say that I have to declare GWT Servlets in Spring Context? Hmmm. I don't think so but I will try this project http://code.google.com/p/spring4gwt/. Thanks for your advise
Firstthumb
I'm not saying you should declare GWT servlet in Spring context. I am, however, saying that Spring autowiring will **NOT** work unless both the bean being injected and the bean it's injected into are present in Spring context. I haven't tried spring4gwt; they may be doing behind the scenes processing of GWT servlets to make this possible.
ChssPly76
A: 

Well, the class where the @Autowired annotation resides should also be in the spring context (i.e. annotated with @Component) But I doubt it will work if it is a GWT (i.e. client-side) class.

Bozho
I have searched and found that project http://code.google.com/p/spring4gwt/I will try it.
Firstthumb
A: 

You need to "autowire" your RPC servlets during initialization. Take a look here http://code.google.com/p/gwt-spring-starter-app/

nevermind