代码改变世界

随笔分类 -  spring

Spring retry基本使用

2015-08-07 17:27 by Rollen Holt, 20544 阅读, 收藏, 编辑
摘要: Spring retry基本使用================## 背景介绍在实际工作过程中,**重试**是一个经常使用的手段。比如`MQ`发送消息失败,会采取重试手段,比如工程中使用`RPC`请求外部服务,可能因为网络波动出现超时而采取重试手段......可以看见重试操作是非常常见的一种处理问题... 阅读全文

Cacheable key collision with DefaultKeyGenerator

2015-01-07 01:06 by Rollen Holt, 1031 阅读, 收藏, 编辑
摘要: The default is to use the hashcode of each parameter and create another (32-bit) hash code. Obviously this can easily generate collisions. This should... 阅读全文

Spring Cache 介绍

2015-01-05 01:45 by Rollen Holt, 73934 阅读, 收藏, 编辑
摘要: Spring Cache================`缓存`是实际工作中非常常用的一种提高性能的方法, 我们会在许多场景下来使用缓存。本文通过一个简单的例子进行展开,通过对比我们原来的自定义缓存和 spring 的基于注释的 cache 配置方法,展现了 spring cache 的强大之处,然... 阅读全文

Spring MVC exception - Invoking request method resulted in exception : public static native long java.lang.System.currentTimeMillis()

2014-10-11 11:32 by Rollen Holt, 4067 阅读, 收藏, 编辑
摘要: 最近在线上系统发现下面的异常信息: 2014-10-11 11:14:09 ERROR [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveE... 阅读全文

no suitable HttpMessageConverter found for request type [java.lang.Integer]

2014-08-25 12:08 by Rollen Holt, 31919 阅读, 收藏, 编辑
摘要: 今天在使用`Spring Template`的时候遇到了这个异常: no suitable HttpMessageConverter found for request type [java.lang.Integer]Google了一下然后在stackoverflow上面找到了解决方案:I ha... 阅读全文

Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found

2014-08-04 16:20 by Rollen Holt, 70133 阅读, 收藏, 编辑
摘要: 今天在完成项目的时候遇到了下面的异常信息: 04-Aug-2014 15:49:27.894 SEVERE [http-apr-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() f... 阅读全文

Spring表单参数绑定中对“is”开头的boolean类型字段的的处理

2014-07-23 17:46 by Rollen Holt, 6695 阅读, 收藏, 编辑
摘要: 之前在新浪微博上面发了一个微薄: 弱弱的发现在定义boolean类型的时候最好不要使用“is”开头,可以避免一些问题哦然后有一些朋友朋友问我为什么,当时比较忙,现在写篇文章举一个例子,回复一下这个问题。最近在使用Spring MVC的时候vo定义了一个字段,一开始字段名字为:isAddCertif... 阅读全文

使用注解属性绑定

2014-04-29 19:28 by Rollen Holt, 4722 阅读, 收藏, 编辑
摘要: 大家应该知道在Spring中有一个注解@Value,他可以帮助我们来讲Spring加载的配置文件(*.perperties)文件中的信息自动的注入到我们的非静态属性中的。一般情况下我们会这样使用:1. 首先在Spring的配置文件中加载属性文件:然后在Java代码中使用@Value注解就可以注入值... 阅读全文

RESTful的理解

2014-04-27 01:16 by Rollen Holt, 29110 阅读, 收藏, 编辑
摘要: REST(Representational State Transfer ),有中文翻译为"具象状态传输"(也有:"代表性状态传输")。是由 Roy Thomas Fielding博士 在2000年就读加州大学欧文分校期间在学术论文中提出的一个术语。他首次系统全面地阐述了REST的架构风格和设计思想... 阅读全文

Spring 文件上传功能

2014-04-26 23:18 by Rollen Holt, 47316 阅读, 收藏, 编辑
摘要: 本篇文章,我们要来做一个Spring的文件上传功能:1. 创建一个Maven的web工程,然后配置pom.xml文件,增加依赖: org.springframework.boot spring-boot-starter-web 1.0... 阅读全文

使用Spring Boot来加速Java web项目的开发

2014-04-26 22:57 by Rollen Holt, 121674 阅读, 收藏, 编辑
摘要: 我想,现在企业级的Java web项目应该或多或少都会使用到Spring框架的。回首我们以前使用Spring框架的时候,我们需要首先在(如果你使用Maven的话)pom文件中增加对相关的的依赖(使用gradle来构建的话基本也一样)然后新建Spring相关的xml文件,而且往往那些xml文件还不会少... 阅读全文

当spring 容器初始化完成后执行某个方法

2014-03-19 21:47 by Rollen Holt, 96027 阅读, 收藏, 编辑
摘要: 在做web项目开发中,尤其是企业级应用开发的时候,往往会在工程启动的时候做许多的前置检查。 比如检查是否使用了我们组禁止使用的Mysql的group_concat函数,如果使用了项目就不能启动,并指出哪个文件的xml文件使用了这个函数。 而在Spring的web项目中,我们可以介入Spring的启动 阅读全文

Consuming a RESTful Web Service

2013-10-22 00:36 by Rollen Holt, 1241 阅读, 收藏, 编辑
摘要: 本篇文章将介绍使用Spring来建立RESTful的Web Service。 我们通过一个例子来说明这篇文章:这个例子将会使用Spring的RestTemplate来从Facebook的提供的API中获取一些信息。然后对这些信息进行一些处理。Facebook的API为:http://graph.facebook.com/gopivotal 其实在这个例子中,这个API只是为了掩饰用,并没有特别的含义。这个例子也只是为了说明从一个在线的接口中获取一些数据并进行处理。 当我们通过浏览器或者curl请求这个路径的时候会返回数据格式为: { "id": "16111270 阅读全文

Spring 3 MVC And JSR303 @Valid Example

2012-12-27 20:19 by Rollen Holt, 3781 阅读, 收藏, 编辑
摘要: package com.xxx.training.controller;import com.xxx.training.model.User;import org.springframework.stereotype.Controller;import org.springframework.val... 阅读全文

Spring 表单处理

2012-12-27 19:27 by Rollen Holt, 3313 阅读, 收藏, 编辑
摘要: 1. SimpleFormController vs @ControllerIn XML-based Spring MVC web application, you create a form controller by extending theSimpleFormControllerclass.In annotation-based, you can use@Controllerinstead.SimpleFormControllerpublic class CustomerController extends SimpleFormController{ //...}Annota... 阅读全文

Spring MVC视图解析器:配置多个视图解析器的优先级

2012-12-27 17:08 by Rollen Holt, 26749 阅读, 收藏, 编辑
摘要: 问题在Spring MVC应用程序中,我们经常需要应用一些视图解析器策略来解析视图名称。例如,联合使用三个视图解析器:InternalResourceViewResolver、ResourceBundleViewResolver和XmlViewResolver。但是,如果返回了一个视图的名称,那么,... 阅读全文

Spring MVC视图解析器:Spring MVC ResourceBundleViewResolver示例

2012-12-27 17:00 by Rollen Holt, 7294 阅读, 收藏, 编辑
摘要: 在Spring MVC中,使用ResourceBundleViewResolver基于“.properties”文件中的视图bean来解析“视图名称”。默认地,ResourceBundleViewResolver将从位于项目class路径根目录下的文件views.properties中加载视图bea... 阅读全文

Spring MVC视图解析器:Spring MVC XmlViewResolver示例

2012-12-27 16:35 by Rollen Holt, 8638 阅读, 收藏, 编辑
摘要: 在Spring MVC中,使用XmlViewResolver基于XML文件中的视图bean来解析“视图名称”。默认地,XmlViewResolver将从/WEB-INF/views.xml中加载视图bean,不过,这个位置可以通过“location”属性覆盖:<beans ...> <bean class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="location"> <value>/WEB-INF/spr 阅读全文

Spring中bean注入前后的一些操作:

2012-12-27 10:47 by Rollen Holt, 3445 阅读, 收藏, 编辑
摘要: InitializingBean 和DisposableBeaninit-method 和destroy-method@PostConstruct 和@PreDestroyIn Spring,InitializingBeanandDisposableBeanare two marker interfaces, a useful way for Spring to perform certain actions upon bean initialization and destruction.For bean implemented InitializingBean, it will runaf 阅读全文

Spring的属性依赖检查

2012-12-27 10:40 by Rollen Holt, 2969 阅读, 收藏, 编辑
摘要: Spring支持4种依赖检查:默认的是nonenone – No dependency checking.simple – If any properties of primitive type (int, long,double…) and collection types (map, list..) have not been set, UnsatisfiedDependencyException will be thrown.objects – If any properties of object type have not been set, UnsatisfiedDependenc 阅读全文