我有一個簡單的問題,那就是如何運行在Glassfish服務器上使用Spring框架的應用程序?也就是說,如何讓它在Spring容器的控制下運行?我是否需要擴展服務器或其他什麼東西,我找不到有關這方面的很多信息,我讀到的關於OSGI模塊的東西,只是困惑了我。Glassfish + Spring
4
A
回答
7
基本上你使用web.xml來啓動一個監聽器,然後映射一個或多個Spring Dispatcher servlet。您在dispatcher-servlet.xml
中定義控制器bean,注入您在applicationContext中定義的bean,並從那裏向下級聯。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
etc etc
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/myApp/*</url-pattern>
</servlet-mapping>
1
在部署描述符(web.xml),定義的Servlet監聽器和上下文PARAM。
上下文參數 - spring bean文件的文件位置。 (野生字符允許和皮卡一堆下的文件,這是野生字符選擇。)
聽者 - 春天班,將聽取請求。不同的類可用於不同的目的。
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- All file ends with Context.xml under web-inf folder -->
<param-value>WEB-INF/*Context.xml</param-value>
</context-param>
<listener>
<display-name>Spring context loader</display-name>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<!-- use following if you want to use request scope -->
<!-- org.springframework.web.context.request.RequestContextListener -->
</listener>
<servlet>
<servlet-name>servlet name</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>name</servlet-name>
<url-pattern>/URLName</url-pattern>
</servlet-mapping>
相關問題
- 1. Spring和tomcat或Spring和Glassfish
- 2. 在glassfish下登錄spring 3.0?
- 3. Glassfish的404錯誤Spring項目
- 4. Spring/Glassfish 3.1.2陳舊的文件
- 5. 在Glassfish中禁用Spring依賴注入
- 6. 使用Glassfish和Spring更改JMS設置
- 7. Glassfish和Spring設置教程/例子?
- 8. Glassfish和Spring Boot:.war重新部署失敗
- 9. Glassfish上的Spring - 獲取Hibernate參數記錄?
- 10. @Async支持不能與glassfish 3.1.2和Spring 3.1.2一起工作
- 11. Glassfish中使用JSF託管bean的spring bean的問題
- 12. 從Glassfish with EJB遷移到Google App Engine與Spring
- 13. 在GlassFish和Spring 3中使用CommonJ實現
- 14. 無法在Glassfish 4.1上部署Spring Boot應用程序
- 15. 在Glassfish 4上運行Spring 3應用程序
- 16. Spring集成卡夫卡outboundchannel通過GlassFish的
- 17. 將Spring應用程序從Glassfish移動到Tomcat
- 18. Glassfish和EclipseLink不能正常工作的entitymanager的Spring注入
- 19. Glassfish 3.1上的Spring Roo webapp持久性錯誤
- 20. glassfish和h2database問題
- 21. Glassfish&Apache
- 22. Glassfish Tomcat
- 23. Glassfish javax.ejb.EJBException
- 24. GlassFish中
- 25. Glassfish [java.lang.reflect.InvocationTargetException]
- 26. Glassfish - java.lang.NoClassDefFoundError
- 27. 在GlassFish
- 28. Glassfish上
- 29. glassfish hosting
- 30. SunPKCS11 glassfish