Announcement Announcement Module
Collapse
No announcement yet.
How to let Groovy dynamic Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to let Groovy dynamic

    I have integrate groovy into spring use groovyscriptfactory, but after I change the groovy file content, I find that it didn't impact the result,
    for example,I have a webcontroller which has a property injected by a bean written by groovy, and then I change this groovy bean method ,I hope that the controller ouput will change too, but not? why? does it dynmaic indeed?

  • #2
    Could you provide a sample that shows your configuration?

    Comment


    • #3
      this is my code:

      Code:
      applicationContext.xml:
      
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
      <beans>
      	<bean id="groovyScriptFactory"
      		class="org.springframework.beans.factory.script.groovy.GroovyScriptFactory">
      		<property name="expirySeconds"><value>1</value></property>
      	</bean>
      	
      	<bean id="groovyAction" singleton="true" factory-bean="groovyScriptFactory" factory-method="create">
      		<constructor-arg index="0"><value>classpath&#58;org/test/GroovyAction.groovy</value></constructor-arg>		
      		<property name="message"><value>error</value></property>
      	</bean>
      </beans>
      
      ww2groovy-servlet.xml&#58;
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
      <beans>
      	<bean id="testController" class="org.kalfen.test.controller.testController">
      		<property name="groovyAction"><ref bean="groovyAction"/></property>
      	</bean> 
      	   
      	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">		<property name="mappings">
      			<props>
      				<prop key="/test.htm">testController</prop>
      			</props>
      		</property>
      	</bean>
      	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      </beans>
      
      
      GroovyAction.groovy&#58;
      package org.springframework.beans.factory.script.groovy
      import com.opensymphony.xwork.Action;
      
      public class TestGroovyAction implements Action &#123;
          property message
      
      
          String execute &#40;&#41; &#123;
              message
          &#125;
      &#125;
      
      testController&#58;
      package org.kalfen.test.controller;
      
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import org.springframework.web.servlet.ModelAndView;
      import org.springframework.web.servlet.mvc.Controller;
      import com.opensymphony.xwork.Action;
      
      public class testController implements Controller &#123;
      
      	public Action groovyAction;
      	
      	public void setGroovyAction&#40;Action groovyAction&#41;&#123;
      		this.groovyAction = groovyAction;
      	&#125;
      	public Action getGroovyAction&#40;&#41;&#123;
      		return this.groovyAction;
      	&#125;
      	
      	
      	public ModelAndView handleRequest&#40;
      		HttpServletRequest arg0,
      		HttpServletResponse arg1&#41;
      		throws Exception &#123;
      		System.out.println&#40;groovyAction.execute&#40;&#41;&#41;;
      			
      		// TODO Auto-generated method stub
      		return null;
      	&#125;
      &#125;

      Comment


      • #4
        I found that in AbstractScript class, the following
        is = context.getResourceLoader().getResource(location). getInputStream();
        always return the same is object, I have set autorefresh to true,so it will read groovy file when reload web page, but I don't know why this code always generate the same object although I have change the groovy file

        Comment

        Working...
        X