使用groovy编写spring的controller(二)

使用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"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
lazy-init="false">
<property name="locations">
<list>
<value>classpath*:easygroovy.properties
</value>
</list>
</property>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="viewNameTranslator"
class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" />
<bean
class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
<bean id="groovyManager" class="com.sillycat.easygroovy.service.impl.GroovyManagerImpl">
</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删除了就好了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值