GWT项目中的Spring配置?
我正在开发一个 GWT-Spring-Hibernate 项目,我想在 GWT Service Servlet 中使用 Spring Autowired 注释,但我的自动注释服务未注入。它为空。是否有我遗漏的配置细节?
我添加
<context:annotation-config />
<context:component-scan base-package="com.org" />
到我的 ApplicationContext.xml 并将我的服务注释为 @Service("myService")
@Autowired
MyService myService; // This is null so WHY?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在初始化期间“自动装配”您的 RPC servlet。看看这里 http://code.google.com/p/gwt -spring-starter-app/
You need to "autowire" your RPC servlets during initialization. Take a look here http://code.google.com/p/gwt-spring-starter-app/
好吧,
@Autowired
注释所在的类也应该在spring上下文中(即用@Component
注释),但我怀疑如果它是GWT它是否会起作用(即客户端)类。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.您尝试将服务注入的类实际上是在 Spring 上下文中声明的 bean 吗?应该是的,否则自动接线将无法工作。
它可以被明确声明,或者,只要它位于“com.org”层次结构中的某个位置,如果它是 注释为 @Component 或 Spring 提供的其他构造型之一。
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.