小编use*_*874的帖子

使用HOT部署的Spring/REST应用程序:Groovy脚本不会在运行时在tomcat启动时从applicationContext.xml动态加载

我正在使用Spring MVC和Groovy将已经存在的Java Web应用程序转换为RESTful Web应用程序.我想要实现的主要功能之一是HOT DEPLOYMENT.我之所以选择groovy是因为我不想对已经实现的业务逻辑(处理程序)进行更改,而且如果我必须在部署后对groovy代码进行更改,我可以轻松地在不重新启动服务器的情况下执行此操作(即在运行时).这可以做到,因为Spring支持动态重新加载groovy脚本(bean).如果它们被更改,它会重新加载动态语言类.

我使用Spring注释将请求URL映射到控制器方法,应用程序部署在tomcat 6.0.35中.

这是web.xml文件

//web.xml

        <?xml version = "1.0" encoding = "UTF-8"?>
        <web-app xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

         <!-- Spring Dispatcher -->
         <servlet>
              <servlet-name>rest</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <load-on-startup>1</load-on-startup>
         </servlet>
         <servlet-mapping>
              <servlet-name>rest</servlet-name>
              <url-pattern>/service/*</url-pattern>
         </servlet-mapping>
        <!-- Loads application context files in addition to  ${contextConfigLocation} -->
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>    

            <!-- Set session timeout to 30 minutes -->
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
    </web-app>
Run Code Online (Sandbox Code Playgroud)

这个groovy文件是DispatcherServlet将请求映射到的控制器.

// UserController.groovy

@Controller
class UserController 
 {
    // This is the method to which the HTTP request is submitted to …
Run Code Online (Sandbox Code Playgroud)

rest groovy spring-mvc tomcat6 spring-annotations

6
推荐指数
1
解决办法
1748
查看次数

标签 统计

groovy ×1

rest ×1

spring-annotations ×1

spring-mvc ×1

tomcat6 ×1