Vâng,
Chúng tôi đã có một kịch bản tương tự cấu hình một thoát Jersey web ứng dụng các dịch vụ sử dụng Xuân cho dependency injection. Jersey webapp của chúng tôi đã mở rộng ContextLoaderListener như sau
public class XServletContextListener extends ContextLoaderListener {
...
@Override
public void contextInitialized(ServletContextEvent arg0) {
super.contextInitialized(arg0);
....
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
super.contextDestroyed(arg0);
....
}
}
nơi ContextLoaderListener là
import org.springframework.web.context.ContextLoaderListener;
Chúng bao gồm các jersey xuân cầu với tất cả mùa xuân phụ thuộc bao gồm applicationContext. xml như sau
<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/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.xxx.*" />
....
....
</beans>
Và rõ ràng là cần thiết để đảm bảo rằng XServletContextListener được bao gồm trong web.xml như sau
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>com.xxx.**.XServletContextListener</listener-class>
</listener>
Tiếp theo là servlet và init-param giá trị của nó và servlet ánh xạ. Bạn rõ ràng có thể áp dụng cấu hình chú thích thay cho ký tự xml trong trường hợp này bạn sẽ cần sử dụng chú thích WebListener.
Chúng tôi sử dụng một loạt các chú thích như
@Component for objects
@Service for services
@Repository for DAOs
@Controller for controllers/resources
@ContextConfiguration for tests
Tất cả mọi thứ được nạp và autowired bởi Spring framework.
Bạn có muốn đưa hạt đậu Xuân vào người nghe này không? –
Tại sao bạn cần mùa xuân để nhận thức được người nghe này? Bạn có thể thêm thông tin về những gì bạn cần đạt được không? –
Đây có phải là những gì bạn đang tìm kiếm không ?. http://stackoverflow.com/questions/8686507/how-to-add-a-hook-to-the-application-context-initialization-event thêm giao diện ApplicationListener và đăng ký một bean sẽ cho phép bạn xử lý vòng đời xuân. Sẽ rất tuyệt nếu bạn có thể cung cấp thêm một chút thông tin được đề cập về những gì bạn đang cố gắng đạt được. Hãy cho tôi biết –