我试图通过以下方式自动将类自动生成WebSocketServlet:
@Configurable(autowire=Autowire.BY_TYPE)
public class MyServlet extends WebSocketServlet {
@Autowired
public MyClass field;
// etc...
}下面是我的配置:
<context:annotation-config />
<context:component-scan base-package="org.*" />
<bean id="config" class="org.*.MyClass">
<!-- a bunch of properties -->
</bean>注意到,只要我在Spring @Controller. ,自动导航器就能正常工作。我不得不退出,因为我不知道如何像对常规servlet那样将WebSocketsServlet映射到@Controller的方法。
知道我可能错过了什么吗?
发布于 2012-10-05 15:15:58
摆脱@Configurable并在servlet init方法中执行以下操作可以完成任务:
@Override
public void init() throws ServletException {
super.init();
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}发布于 2012-10-11 12:08:34
为了使用@Configurable,您需要在旅游上下文中使用这些行:
<context:load-time-weaver aspectj-weaving="true"/>
<context:spring-configured/>
<context:annotation-config />
<context:component-scan base-package="org.*" />此外,我认为您必须参考清单的导入库部分中的spring方面.
我没有成功地让它发挥作用,在Eclipse的处女座论坛上有一篇关于这个的文章。如果你成功了,告诉我怎么做;)
发布于 2012-10-05 10:17:25
根据春季文献
通过使用@Configuration或@Inject注释将Spring注入到一个@Inject类中,可以查找外部化的值:
@Configuration
public class AppConfig {
@Inject Environment env;
@Bean
public MyBean myBean() {
MyBean myBean = new MyBean();
myBean.setName(env.getProperty("bean.name"));
return myBean;
}
}https://stackoverflow.com/questions/12744070
复制相似问题