2013-06-24 3 views
6

पर टॉमकैट स्टार्टअप पर एप्लिकेशनकॉन्टेक्स्ट.एक्सएमएल से गतिशील रूप से लोड नहीं होती है। मैं स्प्रिंग एमवीसी और ग्रोवी का उपयोग कर एक पहले से ही जावा वेब एप्लिकेशन को एक शानदार वेब एप्लिकेशन में परिवर्तित करने की प्रक्रिया में हूं। मुख्य सुविधाओं में से एक जो मैं प्राप्त करना चाहता था वह हॉट डिप्लोमेंट था। मैंने ग्रोवी चुना क्योंकि मैं पहले से ही कार्यान्वित बिजनेस लॉजिक (हैंडलर) में बदलाव नहीं करना चाहता था और अगर मुझे कभी भी तैनाती के बाद ग्रोवी कोड में बदलाव करना पड़ा, तो मैं सर्वर को पुनरारंभ किए बिना आसानी से ऐसा कर सकता था (यानी। क्रम)। यह किया जा सकता है क्योंकि वसंत ग्रोवी स्क्रिप्ट (बीन्स) की गतिशील पुनः लोडिंग का समर्थन करता है। यदि वे बदल जाते हैं तो यह गतिशील भाषाओं के वर्गों को फिर से लोड करता है।हॉट डिप्लॉयमेंट के साथ स्प्रिंग/आरईएसटी एप्लीकेशन: ग्रोवी स्क्रिप्ट रनटाइम

मैं अनुरोध URL के नियंत्रक विधियों को मैप करने के लिए स्प्रिंग एनोटेशन का उपयोग कर रहा हूं और एप्लिकेशन को टॉमकैट 6.0.35 में तैनात किया गया है।

यह इस ग्रूवी फ़ाइल नियंत्रक DispatcherServlet नक्शे जो करने के लिए अनुरोध है 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> 

है।

// UserController.groovy 

@Controller 
class UserController 
{ 
    // This is the method to which the HTTP request is submitted to based on the mapping of the 
    // action field of the form ie. /service/user/login/auth.json 
    @RequestMapping(value="/user/login/auth.{extension:[a-zA-Z]+}", method=RequestMethod.POST) 
    @ResponseBody 
    public String authenticate(
    @PathVariable String extension, 
    @RequestParam(value="username", required=true) String username, 
    @RequestParam(value="password", required=true) String password) 
    { 
     // UserResource makes the backend calls, authenticates a user and returns the result. 
     def user = new UserResource() 
     def result = user.login(name:username, userPassword:password) 

     // Output the result of the query. Method makeView makes a JSON response of the result 
     // and sends to the client(browser) 
     def builder = makeView(extension) 
     { 
      it.login(action:result.action, message:result.message) 
     } 
    } 
    } 

स्प्रिंग कॉन्फ़िगरेशन फ़ाइल निम्नानुसार है जहां मैंने "लैंग: ग्रोवी" टैग का उपयोग किया है जो गतिशील भाषाओं का समर्थन करता है। मैंने रीफ्रेश समय का 5 सेकंड होने का भी उल्लेख किया है, ताकि रनटाइम पर उन ग्रोवी फाइलों में किए गए किसी भी बदलाव को हर 1 सेकंड में देखा जा सके और कक्षाएं फिर से लोड हो जाएं।

//applicationContext.xml 

<?xml version="1.0" encoding="UTF-8"?> 
<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" 
    xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:c="http://www.springframework.org/schema/c" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.1.xsd 
     http://www.springframework.org/schema/util 
     http://www.springframework.org/schema/util/spring-util-3.1.xsd 
     http://www.springframework.org/schema/lang 
     http://www.springframework.org/schema/lang/spring-lang-3.1.xsd"> 

    <context:annotation-config/> 
    <context:component-scan base-package="app.controller,app.resource" /> 

    <lang:groovy id="user" script-source="classpath:controller/UserController.groovy" refresh-check-delay="1000"></lang:groovy> 

    <!-- To enable @RequestMapping process on type level and method level --> 
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 

    <!-- Resolves view names to template resources within the directory --> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/"/> 
     <property name="suffix" value=".html"/> 
    </bean> 

</beans> 

मैं अपने Buildpath और ग्रूवी संकलक तदनुसार कॉन्फ़िगर किया है, ताकि सभी ग्रूवी स्क्रिप्ट के बजाय सीधे लक्ष्य फ़ोल्डर में प्रतिलिपि मिल वर्ग फ़ाइलों को संकलित हो रही।

मुख्य समस्या
जब मैं एक बिल्ला सर्वर में इस परियोजना को तैनात है, यह लोड करता है सब वसंत सेम ScriptProcessor सहित आवश्यक। अब, जब मैं अपने ब्राउज़र पर जाते हैं, प्रपत्र लोड करते हैं, और प्रमाणीकरण फ़ॉर्म सबमिट करने का प्रयास करते हैं, मैं बिलाव में निम्न त्रुटि लॉग ऑन करें:

15:20:09 WARN - No mapping found for HTTP request with URI [/service/user/login/auth.json] in DispatcherServlet with name 'rest' 

मैं भी $ TOMCAT_DIR/conf/संदर्भ में परिवर्तन किए हैं .xml संसाधनों और जार

<Context antiResourceLocking="true" antiJARLocking="true" reloadable="true" privileged="true"> 
. 
. 
.</Context> 

antilock को हालांकि, अगर मैं कॉन्फ़िगर अपने प्रोजेक्ट, बाईटकोड वर्गों में उन ग्रूवी लिपियों संकलन बाहर टिप्पणी "लैंग: ग्रूवी" करने के लिए applicationContext.xml में टैग, और उसके बाद सर्वर को पुनः आरंभ, ग्रोवी स्क्रिप्ट क्लास फाइलों में संकलित हो जाती है और अनुरोध पूरी तरह से सर्विस किया जाता है। प्रमाणीकरण होता है।

इसके अलावा, अगर मैं टैग के बजाए निम्नलिखित दो पंक्तियों का उपयोग कर अपने अनुप्रयोगकंटेट.एक्सएमएल में गतिशील बीन्स को कॉन्फ़िगर करता हूं, तो मेरे बीन्स डीओ रनटाइम पर गतिशील रूप से बनाए जाते हैं और एनोटेशन एनोटेशन के कारण संबंधित नियंत्रक विधियों में मैप किए जाते हैं ।

<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor" /> 

<bean id ="User" class="org.springframework.scripting.groovy.GroovyScriptFactory"> 
    <constructor-arg value="classpath:controller/UserController.groovy" /> 
</bean> 

लेकिन मुझे नहीं पता कि इस शैली के साथ बीन रीफ्रेशिंग कार्यक्षमता कैसे बनाएं। तो मुझे लगता है कि टैग ग्रोवी स्क्रिप्ट को संसाधित करने के तरीके के साथ एक मुद्दा है।

मैं वास्तव में इस पर कुछ मदद की सराहना करता हूं। मैंने पूरे इंटरनेट पर खोज की है और ट्यूटोरियल की एक अनंत संख्या पढ़ी है, और वहां वर्णित सटीक प्रक्रिया का पालन किया है। लेकिन मैं यह नहीं पता कि क्या गलत हो रहा है।

कृपया इस समस्या को हल करने में मेरी सहायता करें।

धन्यवाद।

उत्तर

0

संकलित जावा/ग्रोवी के साथ नियंत्रक बनाने का प्रयास करें और इसे वास्तविक कार्य करने की निर्भरता के रूप में ग्रोवी 'स्क्रिप्ट' को इंजेक्शन देने दें। मुझे पहले ऐसा करने की याद आ रही है और यह एनोटेशन या जिस तरह से स्प्रिंग लोड नियंत्रक हो सकता है जो 'स्क्रिप्ट' आपके लिए सही तरीके से काम नहीं करता है।

संबंधित मुद्दे