2009-11-19 23 views
3

我正在开发一个GWT-Spring-Hibernate项目,我想在GWT服务Servlet中使用Spring Autowired注释,但我的自动注释注释服务没有注入。它是空的。有没有我错过的配置细节?GWT项目中的Spring配置?

我添加

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

我applicationContext.xml中,我已经注解我的服务为@Service( “为myService”)

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

回答

2

那么,@Autowired注释所在的类也应该在春天的环境中(即用@Component注释),但是我怀疑它是否适用于GWT(即客户端)类。

+0

我已经搜索并发现该项目http://code.google.com/p/spring4gwt/ 我会试一试。 – firstthumb 2009-11-19 08:42:23

1

类是你想注入你的服务为实际上一个在Spring上下文中声明的bean?应该是,自动布线将无法正常工作。

它可以被明确声明,或者如果它在你的“com.org”层次结构中的某个地方,它将被自动检测出来,如果它是annotated as @Component或Spring提供的其他构造类型之一。

+0

MyService包是com.org和@Service定型注释,所以我认为它足以注入 – firstthumb 2009-11-19 08:33:54

+0

我没有问到MyService。上面的引用:“你正在尝试将**服务**注入到**中的类”。 – ChssPly76 2009-11-19 08:45:23

+0

我在GWT Servlet中调用MyService,所以你说我必须在Spring Context中声明GWT Servlet?嗯。我不这么认为,但我会尝试这个项目http://code.google.com/p/spring4gwt/。感谢您的建议 – firstthumb 2009-11-19 08:54:53