
概述使用groovy
编写spring的controller(二) 3、文件清单 web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app id="cpmis" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLS 使用groovy编写spring的controller(二) 3、文件清单 web.xml文件: <?xml version="1.0" enCoding="UTF-8"?> <web-app ID="cpmis" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext.xml</param-value> </context-param> <Listener> <Listener-class>org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <servlet> <servlet-name>sccl</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sccl</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app> sccl-servlet.xml文件: <?xml version="1.0" enCoding="UTF-8"?> <!DOCTYPE beans PUBliC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> </beans> 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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean ID="propertyConfigurer" lazy-init="false"> <property name="locations"> <List> <value>classpath*:easygroovy.propertIEs </value> </List> </property> </bean> <bean > <property name="prefix" value="/" /> <property name="suffix" value=".Jsp" /> </bean> <bean ID="vIEwnameTranslator" /> <bean /> <bean ID="groovyManager" > </bean> <lang:groovy ID="groovyController" refresh-check-delay="3000" script-source="${groovy.file.path}/groovy/GroovyController.groovy"> <lang:property name="groovyManager" ref="groovyManager" /> </lang:groovy> </beans> easygroovy.propertIEs文件: ############################################### # groovy configuration ############################################### groovy.file.path=file://D:/work/easygroovy GroovyController.groovy文件: package com.sillycat.easygroovy.web; import com.sillycat.easygroovy.model.User; import com.sillycat.easygroovy.service.GroovyManager; import javax.servlet.http.httpServletRequest; import javax.servlet.http.httpServletResponse; import org.springframework.web.servlet.ModelAndVIEw; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; class GroovyController extends MultiActionController { GroovyManager groovyManager ModelAndVIEw main(httpServletRequest request, httpServletResponse response) throws Exception { this.groovyManager.echo() User user = this.groovyManager.get(null) user.setUserPassword("111112") System.out.println("controller test2") return new ModelAndVIEw("Jsp/vIEw","user",user) } } User.java对象文件: package com.sillycat.easygroovy.model; public class User { private Integer ID; private String username; private String userPassword; ...get和set方法 } GroovyManagerImpl.java文件: package com.sillycat.easygroovy.service.impl; import com.sillycat.easygroovy.model.User; import com.sillycat.easygroovy.service.GroovyManager; public class GroovyManagerImpl implements GroovyManager { public voID echo() { System.out.println("success in manager!"); } public User get(Integer ID) { User user = new User(); user.setID(Integer.valueOf(1)); user.setUsername("sillycat"); user.setUserPassword("******"); return user; } } 接口文件GroovyManager.java: package com.sillycat.easygroovy.service; import com.sillycat.easygroovy.model.User; public interface GroovyManager { public voID echo(); public User get(Integer ID); } 问题一: 参考spring2.0.x的例子 E:\book\opensource\spring\spring-framework-2.0.8\samples\showcases\dynamvc 做出来老是报错 报错: unable to resolve class Property,unable to find class for annotation 也没有特意去深究这个annotation了,直接把groovy文件里面的@Property删除了就好了。 总结
以上是内存溢出为你收集整理的使用groovy编写spring的controller(二)全部内容,希望文章能够帮你解决使用groovy编写spring的controller(二)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)