`
太阳神喻
  • 浏览: 106806 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

基于spring3.0.5 mvc 简单用户管理实例

阅读更多

    临时应急做了两个月的ASP.NET,终于又回到Java上来了,还是Java感觉亲切啊。马上要开发一个新的项目,最近感觉spring mvc势头比较猛,就了解了一下,以前觉得spring mvc用起来较麻烦,所以一直用struts2,但了解了一下spring3 mvc,一下子就喜欢上了它,下个项目决定就用它了,RESTful URL、几乎0配置、不需要实现任何接口或继承任何类的Controller、方法级别的拦截,一个方法对应一个url、灵活的方法参数和返回值、多种view、处理ajax的请求更是方便...

   下面的小例子用了spring mvc和hibernate,只是简单的用户增删改查,没有用ajax,ajax的版本在这里:Spring3 MVC + jQuery easyUI 做的ajax版本用户管理(http://www.iteye.com/topic/1081739),给和我一样准备用spring mvc的朋友参考一下吧。jar包如图:

  

web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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">
	
	<!-- 默认的spring配置文件是在WEB-INF下的applicationContext.xml -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<filter>
		<filter-name>Set Character Encoding</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value><!-- 强制进行转码 -->
		</init-param>
	</filter>
	
	<filter-mapping>
		<filter-name>Set Character Encoding</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<!-- 默认所对应的配置文件是WEB-INF下的{servlet-name}-servlet.xml,这里便是:spring3-servlet.xml -->
	<servlet>
		<servlet-name>spring3</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>spring3</servlet-name>
		<!-- 这里可以用 / 但不能用 /* ,拦截了所有请求会导致静态资源无法访问,所以要在spring3-servlet.xml中配置mvc:resources -->
		<url-pattern>/</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>
 
 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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation=" 
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd 
          http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" default-autowire="byName">
		<!-- 注意上面的default-autowire="byName",如果没有这个声明那么HibernateDaoSupport中的sessionFactory不会被注入 -->
		<!-- 约定优于配置,约定优于配置 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://127.0.0.1:3306/test"></property>
		<property name="username" value="root"></property>
		<property name="password" value="root"></property>
	</bean>
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
       <property name="mappingDirectoryLocations">
         <list><!-- 这里直接映射的pojo类所在的包,简单方便不用没次加一个pojo类都需要到这里来添加 -->
            <value>classpath:com/fsj/spring/model</value>
         </list>
       </property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
				</prop>
				<prop key="hibernate.show_sql">
					true
				</prop>
			</props>
		</property>
	</bean>
	
	<!-- 自动扫描组件,这里要把web下面的 controller去除,他们是在spring3-servlet.xml中配置的,如果不去除会影响事务管理的。-->
	<context:component-scan base-package="com.fsj.spring">
		<context:exclude-filter type="regex" expression="com.fsj.spring.web.*"/>
	</context:component-scan>
	
	<!-- 下面是配置声明式事务管理的,个人感觉比用注解管理事务要简单方便 -->
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<aop:config>
		<aop:advisor pointcut="execution(* com.fsj.spring.service.*Service.*(..))" advice-ref="txAdvice"/>
	</aop:config>

	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true"/>
			<tx:method name="query*" read-only="true"/>
			<tx:method name="find*" read-only="true"/>
			<tx:method name="load*" read-only="true"/>
			<tx:method name="*" rollback-for="Exception"/>
		</tx:attributes>
	</tx:advice>
	
	
</beans>
 
 spring3-servlet.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation=" 
           http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/mvc 
           http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" default-autowire="byName">
	<!-- 约定优于配置,约定优于配置 -->
	
	<!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理,3.04新增功能,需要重新设置spring-mvc-3.0.xsd -->
	<mvc:resources mapping="/img/**" location="/img/"/>
	<mvc:resources mapping="/js/**" location="/js/"/>
	<mvc:resources mapping="/css/**" location="/css/"/>

	<!-- 扫描所有的controller -->
	<context:component-scan base-package="com.fsj.spring.web" />

	<!-- InternalResourceViewResolver默认的就是JstlView所以这里就不用配置viewClass了 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/view/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	<!-- 启用基于注解的处理器映射,添加拦截器,类级别的处理器映射 -->
	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <list>
                <bean class="com.fsj.spring.util.MyHandlerInterceptor"/>
            </list>
        </property>
	</bean>
	
	<!-- 
	配置一个基于注解的定制的WebBindingInitializer,解决日期转换问题,方法级别的处理器映射,
	有人说该bean要放在context:component-scan前面,要不然不起作用,但我试的放后面也可以啊。
	-->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
	    <property name="cacheSeconds" value="0" />
	    <property name="webBindingInitializer">
	        <bean class="com.fsj.spring.util.MyWebBinding" />
	    </property>
	</bean>
	
</beans> 
 
 log4j的就不贴出来了。
两个HelloWorldController如下:
package com.fsj.spring.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/*
 * 不需要实现任何接口,也不需要继承任何的类
 */
@Controller
public class HelloWorldController {

	/**
	 * 方法都可以接受的参数(参数数量和顺序没有限制): HttpServletRequest,HttpServletResponse,HttpSession(session必须是可用的) ,PrintWriter,Map,Model,@PathVariable(任意多个), @RequestParam(任意多个), @CookieValue (任意多个),@RequestHeader,Object(pojo对象) ,BindingResult等等
	 * 
	 * 返回值可以是:String(视图名),void(用于直接response),ModelAndView,Map ,Model,任意其它任意类型的对象(默认放入model中,名称即类型的首字母改成小写),视图名默认是请求路径
	 */
	@RequestMapping("/helloWorld")
	public ModelAndView helloWorld() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("login");
		mav.addObject("message", "Hello World!");
		return mav;
	}
}
 
package com.fsj.spring.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.fsj.spring.model.TDept;
import com.fsj.spring.model.TUser;
import com.fsj.spring.service.IDeptService;
import com.fsj.spring.service.IUserService;
import com.fsj.spring.util.Constants;

@Controller
@RequestMapping("/user")
public class UserController {
	
	private IUserService userService;
	private IDeptService deptService;
	
	public IDeptService getDeptService() {
		return deptService;
	}

	public void setDeptService(IDeptService deptService) {
		this.deptService = deptService;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String login(@RequestParam String name,@RequestParam String password,Model model,HttpServletRequest request) throws Exception{
		TUser user1 = userService.getUserByName(name);
		if(user1 == null) {
			model.addAttribute("message", "用户不存在");
			return "login";
		}else if(password == null || !password.equals(user1.getPassword()) ){
			model.addAttribute("message", "密码错误");
			return "login";
		}else {
			request.getSession().setAttribute(Constants.USER_INFO_SESSION, user1);
			return "welcome";
		}
	}
	
	@RequestMapping(value="/login1",method=RequestMethod.POST)
	public String login1(TUser user,HttpServletRequest request,Model model) throws Exception{
		TUser user1 = userService.getUserByName(user.getName());
		if(user1 == null) {
			model.addAttribute("message", "用户不存在");
			return "login";
		}else if(user.getPassword() == null || !user.getPassword().equals(user1.getPassword()) ){
			model.addAttribute("message", "密码错误");
			return "login";
		}else {
			request.getSession().setAttribute(Constants.USER_INFO_SESSION, user1);
			return "welcome";
		}
	}
	
	@RequestMapping(value="/list")
	public String list(Model model,HttpServletRequest request) throws Exception {
		List<TUser> userList = userService.getUserList();
		model.addAttribute("userList", userList);
		List<TDept> deptList = deptService.getDeptList();
		model.addAttribute("deptList", deptList);
		if(StringUtils.isNotBlank(request.getParameter("resMess")) && StringUtils.isNotBlank(request.getParameter("opeMess"))) {
			model.addAttribute("message",setOperateMessage(request.getParameter("resMess"),request.getParameter("opeMess"),"用户"));
		}
		return "user/list";
	}

	private String setOperateMessage(String resMess,String opeMess,String modMess) {
		//TODO 以后可以和写日志结合在一起
		String ope = "";
		String res = "";
		if(Constants.OPERATE_TYPE_ADD.equals(opeMess)) {
			ope = "增加";
		}else if(Constants.OPERATE_TYPE_UPDATE.equals(opeMess)) {
			ope = "更新";
		}else if(Constants.OPERATE_TYPE_DELETE.equals(opeMess)) {
			ope = "删除";
		}
		
		if(Constants.RESULT_SUCCESS.equals(resMess)) {
			res = "成功";
		}else if(Constants.RESULT_FAILED.equals(resMess)) {
			res = "失败";
		}
		return ope + modMess + res;
	}
	
	/*
	 * 同样的请求路径 user/add 如果是get请求就转到增加页面去,如果是post请求就做add操作
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String toAdd(Model model) throws Exception{
		List<TDept> deptList = deptService.getDeptList();
		model.addAttribute("deptList", deptList);
		return "user/add";
	}
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String doAdd(TUser user,Model model) throws Exception{
		try {
			userService.addUser(user);
			model.addAttribute("resMess", Constants.RESULT_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("resMess", Constants.RESULT_FAILED);
			throw e;
		}
		model.addAttribute("opeMess", Constants.OPERATE_TYPE_ADD);
		
		//重定向,防止重复提交,当然这样不能完全解决重复提交的问题,只是简单处理一下,若要较好的防止重复提交可以结合token做,
		//以“/”开关,相对于当前项目根路径,不以“/”开关,相对于当前路径
		//return "redirect:/user/list"; 
		return "redirect:list"; 
	}
	
	/*
	 * Restful模式路径:
	 * 注意这里/update/{id}和@PathVariable("id")中id要一致,这样不管用debug模式还是release模式编译都没问题
	 * 也可以简写成@PathVariable int id,但这样只能以debug模式编译的时候正确,如果用release编译就不正确了,因为如果用release模式编译会把参数的名字改变的
	 * 一般IDE工具都是以debug模式编译的,javac是以release模式编译的
	 * 同样的请求路径 user/update 如果是get请求就转到增加页面去,如果是post请求就做update操作
	 */
	@RequestMapping(value="/update/{id}",method=RequestMethod.GET)
	public String toUpdate(@PathVariable("id") int id, Model model) throws Exception{
		model.addAttribute("user",userService.getUserById(id));
		model.addAttribute("deptList", deptService.getDeptList());
		return "user/update";
	}
	@RequestMapping(value="/update/{id}",method=RequestMethod.POST)
	public String doUpdate(@PathVariable("id") int id, TUser user,Model model) throws Exception{
		try {
			userService.updateUser(user);
			model.addAttribute("resMess", Constants.RESULT_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("resMess", Constants.RESULT_FAILED);
			throw e;
		}
		model.addAttribute("opeMess", Constants.OPERATE_TYPE_UPDATE);
		//return "redirect:../list"; 
		//重定向,防止重复提交,以“/”开关,相对于当前项目根路径,不以“/”开关,相对于当前路径
		return "redirect:/user/list"; 
	}
	
	@RequestMapping(value="/delete/{id}")
	public String delete(@PathVariable("id") int id,Model model)throws Exception{
		try {
			userService.deleteUser(id);
			model.addAttribute("resMess", Constants.RESULT_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("resMess", Constants.RESULT_FAILED);
			throw e;
		}
		model.addAttribute("opeMess", Constants.OPERATE_TYPE_DELETE);
		return "redirect:/user/list";//重定向
	}
}
 
 下面的例子中没有jar包,jar太大了超过10M了,请自己加jar包

 

 

 

  • 大小: 13.6 KB
分享到:
评论
67 楼 herolantian 2011-06-09  
我还是比较喜欢用hibernate的注解做关系映射,spring的注解也很方便,不需要你生成set和get了
66 楼 太阳神喻 2011-06-09  
supben 写道
private IDeptDao deptDao;

public IDeptDao getDeptDao() {
return deptDao;
}

弱弱的问下,这里为什么不用加 @Autowired 啊?

因为有这个:default-autowire="byName"
65 楼 lanmaokyle 2011-06-09  
在Jboss5.0GA上运行不了
17:25:28,015 INFO  [[/spring3]] Initializing Spring root WebApplicationContext
17:25:28,031 INFO  [STDOUT] 2011-06-09 17:25:28  INFO [ContextLoader.java:187] org.springframework.web.context.ContextLoader.initWebApplicationContext() - Root WebApplicationContext: initialization started
17:25:28,078 INFO  [STDOUT] 2011-06-09 17:25:28  INFO [AbstractApplicationContext.java:456] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh() - Refreshing Root WebApplicationContext: startup date [Thu Jun 09 17:25:28 CST 2011]; root of context hierarchy
17:25:28,171 INFO  [STDOUT] 2011-06-09 17:25:28  INFO [XmlBeanDefinitionReader.java:315] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions() - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
17:25:29,281 INFO  [STDOUT] 2011-06-09 17:25:29  INFO [DefaultListableBeanFactory.java:555] org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons() - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e839f2: defining beans [dataSource,sessionFactory,deptDao,userDao,deptService,userService,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,txManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice]; root of factory hierarchy
17:25:29,843 INFO  [STDOUT] 2011-06-09 17:25:29  INFO [Version.java:37] org.hibernate.annotations.common.Version.<clinit>() - Hibernate Commons Annotations 3.2.0.Final
17:25:29,859 INFO  [STDOUT] 2011-06-09 17:25:29  INFO [Environment.java:593] org.hibernate.cfg.Environment.<clinit>() - Hibernate 3.6.0.Final
17:25:29,875 INFO  [STDOUT] 2011-06-09 17:25:29  INFO [Environment.java:626] org.hibernate.cfg.Environment.<clinit>() - hibernate.properties not found
17:25:29,875 INFO  [STDOUT] 2011-06-09 17:25:29  INFO [Environment.java:804] org.hibernate.cfg.Environment.buildBytecodeProvider() - Bytecode provider name : javassist
17:25:29,890 INFO  [STDOUT] 2011-06-09 17:25:29  INFO [Environment.java:685] org.hibernate.cfg.Environment.<clinit>() - using JDK 1.4 java.sql.Timestamp handling
17:25:30,062 INFO  [STDOUT] 2011-06-09 17:25:30  INFO [Configuration.java:492] org.hibernate.cfg.Configuration.addFile() - Reading mappings from file: D:\jboss-5.0.0.GA\server\default\deploy\spring3.war\WEB-INF\classes\com\fsj\spring\model\TDept.hbm.xml
17:25:31,703 INFO  [STDOUT] 2011-06-09 17:25:31  WARN [DTDEntityResolver.java:73] org.hibernate.util.DTDEntityResolver.resolveEntity() - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
17:25:31,734 INFO  [STDOUT] 2011-06-09 17:25:31  INFO [Configuration.java:492] org.hibernate.cfg.Configuration.addFile() - Reading mappings from file: D:\jboss-5.0.0.GA\server\default\deploy\spring3.war\WEB-INF\classes\com\fsj\spring\model\TUser.hbm.xml
17:25:31,734 INFO  [STDOUT] 2011-06-09 17:25:31  WARN [DTDEntityResolver.java:73] org.hibernate.util.DTDEntityResolver.resolveEntity() - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
17:25:31,828 INFO  [STDOUT] 2011-06-09 17:25:31  INFO [HbmBinder.java:350] org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues() - Mapping class: com.fsj.spring.model.TDept -> t_dept
17:25:31,843 INFO  [STDOUT] 2011-06-09 17:25:31  INFO [HbmBinder.java:350] org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues() - Mapping class: com.fsj.spring.model.TUser -> t_user
17:25:31,875 INFO  [STDOUT] 2011-06-09 17:25:31  INFO [DefaultSingletonBeanRegistry.java:422] org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons() - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e839f2: defining beans [dataSource,sessionFactory,deptDao,userDao,deptService,userService,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,txManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice]; root of factory hierarchy
17:25:31,906 INFO  [STDOUT] 2011-06-09 17:25:31 ERROR [ContextLoader.java:220] org.springframework.web.context.ContextLoader.initWebApplicationContext() - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
	at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:367)
	at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:146)
	at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:460)
	at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
	at org.jboss.web.deployers.WebModule.start(WebModule.java:96)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
	at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
	at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
	at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
	at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
	at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
	at $Proxy36.start(Unknown Source)
	at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
	at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
	at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
	at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
	at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
	at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
	at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
	at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
	at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
	at org.jboss.system.ServiceController.start(ServiceController.java:460)
	at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:146)
	at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:104)
	at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:45)
	at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
	at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
	at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
	at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
	at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
	at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
	at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
	at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:545)
	at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:304)
	at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:205)
	at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:405)
	at org.jboss.Main.boot(Main.java:209)
	at org.jboss.Main$1.run(Main.java:547)
	at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
	at org.hibernate.cfg.Configuration.applyHibernateValidatorLegacyConstraintsOnDDL(Configuration.java:1651)
	at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1623)
	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1415)
	at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(Ab
17:25:31,906 INFO  [STDOUT] stractSessionFactoryBean.java:211)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
	... 70 more
Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
	at java.lang.Class.getConstructor0(Class.java:2706)
	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
	at org.hibernate.cfg.Configuration.applyHibernateValidatorLegacyConstraintsOnDDL(Configuration.java:1639)
	... 77 more
64 楼 supben 2011-06-09  
private IDeptDao deptDao;

public IDeptDao getDeptDao() {
return deptDao;
}

弱弱的问下,这里为什么不用加 @Autowired 啊?
63 楼 supben 2011-06-09  
自动扫描那个不会有问题吧。
他是扫描注解的bean的啊,不会影响到事务吧。
62 楼 river5566 2011-06-09  

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.0.2</version>
</dependency>


<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-asm</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-oxm</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.1</version>
</dependency>
<dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.2.2</version>
</dependency>
<dependency>
    <groupId>commons-pool</groupId>
    <artifactId>commons-pool</artifactId>
    <version>1.5.3</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>aopalliance</groupId>
    <artifactId>aopalliance</artifactId>
    <version>1.0</version>
</dependency>
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.6.8</version>
</dependency>
<dependency>
    <groupId>commons-collections</groupId>
    <artifactId>commons-collections</artifactId>
    <version>3.1</version>
</dependency>
<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-jta_1.1_spec</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.5.8</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.8</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-hibernate3</artifactId>
    <version>2.0.8</version>
</dependency>
<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.9.0.GA</version>
</dependency>
<dependency>
    <groupId>ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>1.2.3</version>
</dependency>
<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>antlr</groupId>
    <artifactId>antlr</artifactId>
    <version>2.7.6</version>
</dependency>


通过maven管理jar,很方便
61 楼 MO_ZHUANG_D 2011-06-09  
当我重新回到软件开发的世界发现自己该努力了
60 楼 wkcause 2011-06-09  
先感谢LZ分享。

在学习中发现几个问题,希望LZ及各位大侠能给予帮助。

源码是下来之后,根据LZ给的jar包截图导入,spring相关的都是3.0.5的,其他的可能会有一些不同。

继承HibernateDaoSupport时,会报错说:HibernateDaoSupport cannot be resolved to a type。

然后我查了一下,说是缺少spring.jar,我当时在spring3中没找到这个,然后添加了spring2.5中的这个jar,就不报错了。

但是还有几个import会报错:
1、org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
2、org.springframework.web.bind.WebDataBinder;
3、org.springframework.web.bind.support.WebBindingInitializer;
4、org.springframework.web.bind.annotation.RequestMapping;
5、org.springframework.web.servlet.ModelAndView;
6、org.apache.commons.lang.StringUtils;
7、org.springframework.web.bind.annotation.PathVariable;
8、org.springframework.web.bind.annotation.RequestMapping;
9、org.springframework.web.bind.annotation.RequestMethod;
10、org.springframework.web.bind.annotation.RequestParam;
还有一个是配置文件里的org.apache.commons.dbcp.BasicDataSource

仔细查了一下jar里面的内容,这个类都有,但不知道为什么不识别。

因为之前我整合过SSH,也被jar的问题困扰过,所以我就把之前项目的jar全部移植过来,没有报错。但是启动tomcat时又会报方法找不到的错:
java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getRegistry();
但是我找了一下,存在这个方法啊。

难道还是jar包冲突的问题,往楼主解答。

59 楼 tiger1102 2011-06-09  
已搞定,不错,学习了

楼主辛苦了
58 楼 太阳神喻 2011-06-09  
没有乱码啊,你是不是没有设置转码?
57 楼 太阳神喻 2011-06-09  
tiger1102 写道
登录时返回的登录提示信息乱码是怎么回事

有乱码吗?还没注意呢
56 楼 太阳神喻 2011-06-09  
river5566 写道
数据库脚本呢?

公司上网不方便,就简单两张表,几个字段,手动建一下就行了,或者把hibernate.hbm2ddl.auto设置为update,项目启动的时候会自动建表的
55 楼 river5566 2011-06-09  
数据库脚本呢?
54 楼 matychen 2011-06-09  
太阳神喻 写道

确定前台传过来的格式是正确的吗?跟一下看什么位置出了错。是有人说
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.*.*.web.interceptor.BindingInitializer" />
</property>
</bean>
要放在<mvc:annotation-driven />后面才可以。


前台是EXTJS post过来的值:
引用

dir DESC
endTime 2011-06-09 23:59:59
limit 10
msisdn
sort startTime
start 0
startTime 2011-06-01 00:00:00


放在了<mvc:annotation-driven />后面也不行呢,

我后来发现在需要转换的controll里面写入就可以了

@Controller
@RequestMapping("/record")
public class RecordController {

	@Autowired
	RecordService recordService;
	@InitBinder
    public void initBinder(WebDataBinder binder) {
        CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true);
        binder.registerCustomEditor(Date.class, editor);
    }


还是不玩这个全局的玩意了。呵呵~~~
53 楼 tiger1102 2011-06-09  
登录时返回的登录提示信息乱码是怎么回事
52 楼 太阳神喻 2011-06-09  
被人投了个隐藏,我违规了吗?
51 楼 太阳神喻 2011-06-09  
matychen 写道
太阳神喻 写道

首先,你为什么要这样写com.*.*.web.interceptor.BindingInitializer,你不能确定你的BindingInitializer具体路径?你的BindingInitializer是怎么写的啊?贴出来看一下,是用的spring自带的日期的属性编辑器还是自定义的?



public class BindingInitializer implements WebBindingInitializer {

	public void initBinder(WebDataBinder binder, WebRequest arg1) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				dateFormat, false));
	}

}


前面有公司名,不好写出来。所以用×号代替了。
不管是用自定义的还是spring自带的,都出现这个问题,我还发现,如果这个写在了最前面,会出现另外一个错误,直接登录页面都不能进入了。

<?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:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd	
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	
       <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer">
			<bean class="com.*.*.web.interceptor.BindingInitializer" />
		</property>
	</bean>

	<!-- 自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
	<context:component-scan base-package="com.*.*.web.*" />
	<!-- controller层的属性和配置文件读入 ,多个用逗号隔开-->
	<context:property-placeholder location="classpath:/config/others/config.properties" />
	<!-- Configures support for @Controllers -->
	<mvc:annotation-driven />

确定前台传过来的格式是正确的吗?跟一下看什么位置出了错。是有人说
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.*.*.web.interceptor.BindingInitializer" />
</property>
</bean>
要放在<mvc:annotation-driven />后面才可以。
50 楼 newwpp 2011-06-09  
写的不错了。我抽时间也学习下
49 楼 matychen 2011-06-09  
太阳神喻 写道

首先,你为什么要这样写com.*.*.web.interceptor.BindingInitializer,你不能确定你的BindingInitializer具体路径?你的BindingInitializer是怎么写的啊?贴出来看一下,是用的spring自带的日期的属性编辑器还是自定义的?



public class BindingInitializer implements WebBindingInitializer {

	public void initBinder(WebDataBinder binder, WebRequest arg1) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				dateFormat, false));
	}

}


前面有公司名,不好写出来。所以用×号代替了。
不管是用自定义的还是spring自带的,都出现这个问题,我还发现,如果这个写在了最前面,会出现另外一个错误,直接登录页面都不能进入了。

<?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:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd	
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	
       <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer">
			<bean class="com.*.*.web.interceptor.BindingInitializer" />
		</property>
	</bean>

	<!-- 自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
	<context:component-scan base-package="com.*.*.web.*" />
	<!-- controller层的属性和配置文件读入 ,多个用逗号隔开-->
	<context:property-placeholder location="classpath:/config/others/config.properties" />
	<!-- Configures support for @Controllers -->
	<mvc:annotation-driven />
48 楼 太阳神喻 2011-06-09  
matychen 写道
引用

<!--  
    配置一个基于注解的定制的WebBindingInitializer,解决日期转换问题,方法级别的处理器映射, 
    有人说该bean要放在context:component-scan前面,要不然不起作用,但我试的放后面也可以啊。 
    --> 
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
        <property name="cacheSeconds" value="0" /> 
        <property name="webBindingInitializer"> 
            <bean class="com.fsj.spring.util.MyWebBinding" /> 
        </property> 
    </bean> 


我这么配置的,怎么不行呢?

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="webBindingInitializer">
			<bean class="com.*.*.web.interceptor.BindingInitializer" />
		</property>
	</bean>



其他地方不用配置吧?这样会出现这个错误
2011-6-9 9:03:28 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet dispatcherServlet threw exception
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'record' on field 'endTime': rejected value [2011-06-09 23:59:59]; codes [typeMismatch.record.endTime,typeMismatch.endTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [record.endTime,endTime]; arguments []; default message [endTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "2011-06-09 23:59:59" from type 'java.lang.String' to type 'java.util.Date'; nested exception is java.lang.IllegalArgumentException]
Field error in object 'record' on field 'startTime': rejected value [2011-06-01 00:00:00]; codes [typeMismatch.record.startTime,typeMismatch.startTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [record.startTime,startTime]; arguments []; default message [startTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'startTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "2011-06-01 00:00:00" from type 'java.lang.String' to type 'java.util.Date'; nested exception is java.lang.IllegalArgumentException]
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:810)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:359)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)


首先,你为什么要这样写com.*.*.web.interceptor.BindingInitializer,你不能确定你的BindingInitializer具体路径?你的BindingInitializer是怎么写的啊?贴出来看一下,是用的spring自带的日期的属性编辑器还是自定义的?

相关推荐

    Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解完整版

    总结,本实例详细介绍了如何使用 Spring MVC 3.0.5、Spring 3.0.5 和 MyBatis 3.0.4 进行全注解开发,涵盖了开发环境配置、Maven 的使用、SSM 整合以及如何在 Eclipse 和 MyEclipse 中集成 Maven。这个教程对于希望...

    Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解

    【Spring MVC 3.0.5 + Spring 3.0.5 + MyBatis3.0.4 全注解实例详解】 Spring MVC 3.0.5 是Spring框架的一个重要版本,它引入了对RESTful风格的支持,使得构建Web应用更加灵活。REST(Representational State ...

    Spring+MVC+3.0.5+Spring+3.0.5+MyBatis3.0.4全注解实例详解

    在本教程中,我们将深入探讨如何使用Spring、Spring MVC 3.0.5以及MyBatis 3.0.4这三个流行的Java框架构建一个全注解的Web应用程序。这个实例详解将帮助开发者理解如何有效地集成这三个组件,实现高效的数据访问和...

    Spring3.0.5所有jar包及每个jar包作用说明文档

    2. **spring-beans.jar**:这个模块主要处理Bean的定义和配置,提供了BeanDefinition和BeanFactory接口,用于解析XML或注解配置,创建和管理Bean实例。 3. **spring-context.jar**:在核心和Bean模块之上,提供了更...

    springsecurity3.0.5应用

    在Spring Security 3.0.5版本中,它提供了许多关键的安全特性,包括用户认证、权限控制、CSRF防护、会话管理等。这个版本是Spring Security发展历史上的一个重要里程碑,它在前一个版本的基础上进行了优化和增强,...

    springMVC3.0.5常用的所有jar包.zip

    Spring MVC 是一个基于 Java 的轻量级 Web 开发框架,它是 Spring 框架的一部分,主要用于构建 MVC(Model-View-Controller)模式的 Web 应用程序。在本压缩包 "springMVC3.0.5常用的所有jar包.zip" 中,包含了一...

    SpringMVC文档.zip_spring mvc

    4. **基于Spring 3.0.5的简单用户管理实例** - 这个文档可能提供了一个使用Spring MVC实现用户管理功能的实际案例,涉及到用户注册、登录、权限控制等常见功能。 5. **Spring MVC 3.x annotated controller的几点...

    Struts2.2.3 Spring3.0.5 Hibernate3.6.5 sql server整合实例源码呈现

    Struts2.2.3、Spring3.0.5和Hibernate3.6.5是Java Web开发中的三个关键框架,它们常被一起使用以构建高效、模块化的应用程序。本实例中,这些框架与SQL Server数据库进行了整合,为开发者提供了一个完整的后端解决...

    spring-framework-3.0.5.reference.rar

    《Spring框架3.0.5参考指南》是Java开发者的重要参考资料,它详尽地阐述了Spring框架3.0.5版本的各项特性和使用方法。Spring Framework作为Java领域最流行的轻量级框架之一,以其模块化设计、依赖注入、面向切面编程...

    Struts 1.3.10+Spring3.0.5+Mybatis3.1.1框架整合全部jar包

    2. **Spring与Struts的集成**:使用Spring的Struts插件,将Action类的实例交给Spring容器管理,通过`&lt;bean&gt;`标签定义Action类并设置scope为prototype,保证每次请求都创建新的Action实例。 3. **Spring与Mybatis的...

    Spring MVC Helloworld实例

    在这个“Spring MVC Helloworld实例”中,我们将会探讨如何利用Spring MVC 3.0.5版本创建一个简单的Hello World应用程序。这个实例包括了所有必要的jar包,使开发者能够快速地开始他们的开发工作。 首先,了解...

    SSH整合(struts 2.2.1,hibernate 3.5.2,spring 3.0.5)

    SSH整合完成后,开发人员可以通过Struts 2处理用户请求,Spring负责管理对象和事务,而Hibernate则完成数据的持久化。这种三层架构使得开发者可以更专注地处理各自领域的任务,提升开发效率,同时也为项目的维护和...

    spring-framework-3.0.5.-source

    1. **BeanFactory**:Spring的核心组件,负责实例化、配置和管理Bean。通过XML配置文件或注解,可以声明Bean及其依赖关系。 2. **ApplicationContext**:扩展了BeanFactory,提供了更多的企业级服务,如消息来源、...

    [spring 3.0] mvc 整合 restful 、maven实例 下载

    在本文中,我们将深入探讨如何在Spring 3.0中整合MVC框架与RESTful服务,并结合Maven构建项目。RESTful(Representational State Transfer)是一种软件架构风格,用于设计网络应用程序,尤其适用于Web服务。Spring ...

    spring-framework-3.0.5.RELEASE-with-docs

    在Web层,Spring MVC是Spring Framework的重要组成部分,它为构建基于Servlet的Web应用提供了模型-视图-控制器(MVC)架构。3.0.5版本中,Spring MVC引入了更多用于处理HTTP请求的新特性,如`@RequestMapping`注解,...

    spring-framework-3.0.5相关jar及工程示例

    工程示例通常会涵盖这些知识点的实际应用,例如创建简单的 MVC 应用、配置和使用 DAO、实现事务管理、使用 AOP 创建切面等。通过分析和运行这些示例,你可以深入理解 Spring 如何在实际项目中发挥作用,从而提升你的...

    activiti+spring+srping Mvc+mybatis+maven整合

    本项目是关于"activiti+spring+spring Mvc+mybatis+maven"的整合,旨在创建一个基于Activiti工作流引擎、Spring、Spring MVC、MyBatis以及Maven的开发环境。下面将详细介绍这些技术及其整合过程。 首先,`activiti`...

Global site tag (gtag.js) - Google Analytics