Spring
共 8 篇文章
Druid connection holder is null autoReconnect=true
问题说明: 在开发spring整合druid链接池(1.0.2版本)的项目时,出现tomcat容器每天早上必须重启一次,否在链接池无法正常使用,其中错误日志如下所示: ### Cause: java.sql.SQLException: connection holder is null ; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; connection holder is null; nested exception is java.sql.SQLException: connection…
2016-11-04 11:34 · Spring
@value 注解设置默认值
在使用spring3.0后,看到了它新增的实用@value注解,一下整理下@value注解设置默认值的方法。 首先需要在spring容器中引入properties文件,例子如下所示: <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:ttt.properties</value> <value>classpath:timer…
2016-09-24 10:32 · Spring
spring mvc redirect 重定向 跳转并传递参数
在项目中做form表单功能提交时,防止用户客户端后退或者刷新时重复提交问题,需要在服务端进行重定向跳转,具体跳转方式有以下几种方式: 公用代码: @RequestMapping(value="/index",method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView index(HttpServletResponse response){ ModelAndView model = new ModelAndView("/home/index"); return model; } 一、使用HttpServletR…
2016-08-05 15:05 · Spring
获取spring ApplicationContext常用方法
背景说明:在开发过程中难免会用到ApplicationContext,在这里记录下笔记。 第一种方式 :根据配置文件获取长用在工具测试类 ApplicationContext applicationContext = new FileSystemXmlApplicationContext("spring.xml"); applicationContext.getBean(TimerBin.class); applicationContext.getBean("timerBin"); 在junit中配置applicationContext 获取bean import org.junit.Tes…
2015-10-29 10:30 · Spring
Spring MVC Zookeeper 统一配置管理
资料摘自:http://www.big-mouth.cn/blog/65.html 背景说明:在基于Spring MVC框架的开发的项目中,由于存在大量的数据库配置、第三方配置信息、环境路径配置信息,一直使用Maven的profile方式来对各种配置信息进行管理(该方式不多做介绍),在维护方面成本较高。针对以上情况,准备借助zookeeper来对不同配置信息进行统一管理(当然其他缓存工具也可以,原理相同)。 第一步 :安装zookeeper服务端(资料较多,这里不多解释) 第二步 :在java中引入apache.zookeeper.ZooKeeper第三方API。 <dependency> …
2015-10-27 10:23 · Spring
MultipartFile upload
今天在使用Spring MVC 进行文件上传时提示出如下错误: java.lang.IllegalStateException: File has been moved - cannot be read again at org.springframework.web.multipart.commons.CommonsMultipartFile.getBytes(CommonsMultipartFile.java:108) ~[spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE] ...... 在网上查了一下File has been moved - can…
2015-04-07 12:48 · Spring
HandlerMapping(1) handler 查找
文章环境说明: spring mvc 版本 3.2.4.RELEASE ,项目中注解方式注册Controller。 众所周知Spring Mvc 中的DispatcherServlet中会使用HandlerMapping 将请求Url解析成为handler处理器。 关于HandlerMapping 实际只有两个突出的功能 注册 和 查找 。由于注册是在spring容器加载时就已将Controller的每一个方法注册成handler,学起来门槛较高。因此此文将先说查找反推出注册。 注:由于Spring Mvc 的版本不同所以相应代码存在出入,以下代码全部出于spring Mvc 3.2.4.R…
2014-11-19 16:34 · Spring
Spring MVC Validator 验证
在使用Spring MVC时,使用了它服务端的验证Validator 验证。遇到了一个问题,在这里记录下。 问题:由于在一个Controller中存在多个可供WEB端使用的方法,根据方法的不同调用不同的验证Validator 进行对参数的验证,例子如下所示: 方法一简单案例: public String amethod(@ModelAttribute("matObjecta")MatObjectA matObjecta, BindingResult bindingResult){ ...... } @InitBinder("matObjecta") public void initBinde…
2014-03-28 10:35 · Spring