
Spring
文章平均质量分 75
kanpiaoxue
这个作者很懒,什么都没留下…
展开
-
spring-retry简单用法
有些场景需要我们对一些异常情况下面的任务进行重试,比如:调用远程的RPC服务,可能由于网络抖动出现第一次调用失败,尝试几次就可以恢复正常。 spring-retry是spring提供的一个基于spring的重试框架,非常好用。官网地址: https://github.com/spring-projects/spring-retry 下面是springboot调用spr...原创 2018-10-15 19:45:50 · 24256 阅读 · 0 评论 -
Spring JUnit 的单测中如何获取当前spring的ApplicationContext上下文
我在写单测的时候(spring环境下的单元测试)想获得当前spring的ApplicationContext上下文。我是这样实现的:import org.junit.Assert;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.BeansException...原创 2014-12-11 14:48:33 · 2967 阅读 · 0 评论 -
Spring使用@Autowired不能注入BlockingQueue的问题
今天遇到一个问题,使用spring4配置BlockingQueue,在Java代码里面使用@Autowired注释方式注入该BlockingQueue,一直报错。我的代码如下: @Autowired private BlockingQueue<CoreTask> alarmInnerQueue; 我的XML如下:<bean id="a...原创 2014-12-09 14:25:53 · 718 阅读 · 0 评论 -
Spring如何注入Date类型的变量
地址: http://k2java.blogspot.com/2011/04/spring-how-to-pass-date-into-bean.html Thursday, April 14, 2011Spring – How to pass a Date into bean property (CustomDateEditor )Simple method may n...原创 2014-12-09 13:59:35 · 752 阅读 · 0 评论 -
spring ehcache 单测报错:ehcache具有相同的名称的解决方案
地址: http://www.captaindebug.com/2012/09/spring-31-caching-and-ehcache.html#.VHPs-568eCk Tuesday, 25 September 2012Spring 3.1: Caching and EhCache If you look around the web for exam...原创 2014-11-25 10:44:42 · 585 阅读 · 0 评论 -
如何在程序中使用classpath里面的文件呢?
Resource resource = new ClassPathResource("ehcache-console.xml"); 上面的这段代码,使用了classpath里面的一个Ehcache的xml配置文件。为了达到这个目的,我使用了spring提供的 org.springframework.core.io.Resource 接口以及它的一个实现类。 ...原创 2014-11-19 17:42:34 · 105 阅读 · 0 评论 -
SimpleJdbcInsert异常:InvalidDataAccessApiUsageException: Configuration can't
今天使用 org.springframework.jdbc.core.simple.SimpleJdbcInsert来进行一些操作,代码如下: @Repository("auditLogDao")public class AuditLogDaoImpl implements AuditLogDao { private static final Logger LOGG...原创 2015-12-18 14:52:48 · 240 阅读 · 0 评论 -
Configuration can't be altered once the class has been compiled or used
使用Spring org.springframework.jdbc.core.simple.SimpleJdbcInsert获得table的元数据的时候,报错: org.springframework.dao.InvalidDataAccessApiUsageException: Configuration can't be altered once the class has been...原创 2014-11-05 19:31:46 · 277 阅读 · 0 评论 -
Spring整合JUnit4测试使用注解引入多个配置文件
我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个。我们在类的注释上面会这样写:@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = "classpath*:spring-ctx-application.xml") 但有的时候我们的项目很复杂,其中的spr...原创 2014-11-03 15:16:19 · 405 阅读 · 0 评论 -
关于系统中使用多个PropertyPlaceholderConfigurer的配置
应用自: http://seraph115.iteye.com/blog/435165================================================================================ 多数的鲜为人知方法都是因为有着罕见的应用,就比如说Spring中PropertyPlaceholderConfigurer这个...原创 2014-10-22 16:27:38 · 105 阅读 · 0 评论 -
Spring mvc controller AOP 失效问题
http://stackoverflow.com/questions/17834958/spring-aop-is-not-working-in-with-mvc-structure?rq=1 You are here: Home » Development » Spring AOP Advice on Annotated ControllersSpring AOP ...原创 2015-11-20 19:29:43 · 370 阅读 · 0 评论 -
spring拦截器中的事务管理
引用自: http://janh.iteye.com/blog/71030 http://janh.iteye.com/blog/71030 写道探讨一下spring拦截器中的数据库操作和事务管理。 大家知道spring中的事务管理是通过AOP代理来实现的,对被代理对象的每个方法进行拦截,在方法执行前启动事务,方法执行完后根据是否有异常和异常的种类进行提交或回滚。 如果要...原创 2016-09-07 11:49:39 · 248 阅读 · 0 评论 -
RestTemplate访问Protobuf
使用RestTemplate访问google的protobuf的例子。其实很简单,Client端的代码如下: RestTemplate restTemplate = new RestTemplate();byte[] rs = restTemplate.getForObject(url, byte[].class, args);ProtobufResult.PBResult o...原创 2014-09-28 15:05:20 · 926 阅读 · 0 评论 -
ajax向springmvc传递对象参数
我们在使用前端的ajax技术过程中,有的时候简简单单的向后台的springmvn传递参数,直接使用如下代码即可:(jquery的ajax代码)var options = { url: 'helloworld', method: 'get', dataType: 'json', data: { teamId: 123 },...原创 2017-10-26 11:15:42 · 1063 阅读 · 0 评论 -
透彻的掌握 Spring 中@transactional 的使用
事务管理是应用系统开发中必不可少的一部分。Spring 为事务管理提供了丰富的功能支持。Spring 事务管理分为编码式和声明式的两种方式。编程式事务指的是通过编码方式实现事务;声明式事务基于 AOP,将具体业务逻辑与事务处理解耦。声明式事务管理使业务代码逻辑不受污染, 因此在实际使用中声明式事务用的比较多。声明式事务有两种方式,一种是在配置文件(xml)中做相关的事务规则声明,另一种是基于@T...原创 2018-01-15 10:38:59 · 110 阅读 · 0 评论 -
SpringMVC上传文件、下载文件
<form id="uploadForm" enctype="multipart/form-data"> <span style="margin-right: 65px;">词典名称:</span> <select class="easyui-combobox" style="width: 1原创 2018-02-02 11:02:44 · 96 阅读 · 0 评论 -
Swagger样例
参考地址: https://dzone.com/articles/spring-boot-and-swagger-documenting-restful-servic?edition=407216&utm_source=Daily%20Digest&utm_medium=email&utm_campaign=Daily%20Digest%202018-10-14...原创 2018-10-15 10:23:16 · 1106 阅读 · 0 评论 -
springboot的Quartz使用
public interface Job { void setName(String name); void execute();} import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Comp...原创 2018-10-08 16:24:42 · 427 阅读 · 0 评论 -
springboot学习材料
入门学习资料:官网文档:https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/参考样例: https://www.callicoder.com/categories/spring-boot/参考样例: https://www.cnblogs.com/ityouknow/cat...原创 2018-09-30 10:38:44 · 147 阅读 · 0 评论 -
Spring Boot Actuator metrics monitoring with Prometheus and Grafana
参考地址: https://www.callicoder.com/spring-boot-actuator-metrics-monitoring-dashboard-prometheus-grafana/ Spring Boot Actuator metrics monitoring with Prometheus and Grafana Welcome ...原创 2018-09-28 15:05:34 · 746 阅读 · 0 评论 -
Spring Boot Actuator: Health check, Auditing, Metrics gathering and Monitoring
参考地址: https://www.callicoder.com/spring-boot-actuator/ Spring Boot Actuator: Health check, Auditing, Metrics gathering and Monitoring Spring Boot Actuator module helps you monitor...原创 2018-09-28 15:03:56 · 792 阅读 · 0 评论 -
Spring Boot Quartz Scheduler Example: Building an Email Scheduling app
引用地址: https://www.callicoder.com/spring-boot-quartz-scheduler-email-scheduling-example/ 代码地址: https://github.com/callicoder/spring-boot-quartz-scheduler-email-scheduling Quartz is an...原创 2018-09-28 11:45:17 · 2626 阅读 · 0 评论 -
springboot常用application.yml
application.ymlspring: profiles: active: - dev main: banner-mode: log boot: admin: client: instance: prefer-ip: true mvc: view...原创 2018-09-20 11:47:28 · 808 阅读 · 0 评论 -
spring-boot的日志添加行号
spring-boot-2.0.5.RELEASE的日志默认是不带行号的,对于开发人员来说比较鸡肋。开发人员更喜欢日志中带有代码的行号,方便定位问题。所以我们来修改一下spring-boot-2.0.5.RELEASE的logback的默认配置。找到他的默认配置文件,如下:spring-boot-2.0.5.RELEASE的默认logback的配置文件:需要使用 vim直接查...原创 2018-09-20 11:19:21 · 6210 阅读 · 1 评论 -
springboot的应用开发经验小结
springboot一个主要的特性就是自动配置。只要你把用到的一些关键的功能的类放在classpath里面,它就会自动装配。同时也会引起问题:springboot自己管理了很多依赖jar,它们的版本都是springboot经过冲突测试过的。如果自己贸然引入其他jar和springboot里面的jar重合,比如apache commons 下面的jar,可能引起springboot的运行...原创 2018-09-14 17:47:52 · 344 阅读 · 0 评论 -
springboot的构建信息build-info
我们想在springboot的Actuator上面看见构建信息,需要配置springboot的打包插件。如下: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>s...原创 2018-09-14 17:33:18 · 3958 阅读 · 0 评论 -
spring配置ThreadPoolExecutor
我想使用JDK自带的线程池,如何使用spring配置呢? package org.kanpiaoxue.example.utils;import java.util.concurrent.ThreadFactory;import org.apache.commons.lang3.StringUtils;import org.apache.commons.lang...原创 2018-08-01 20:56:05 · 853 阅读 · 1 评论 -
Spring @Value的用法
参考: https://blog.youkuaiyun.com/hry2015/article/details/72353994https://blog.youkuaiyun.com/hry2015/article/details/72453920为@Value设置默认值。【注意】不设置默认值的时候,而且配置文件中找不到配置项,spring启动的时候会报错。设置默认值的方法: ...原创 2018-03-23 15:12:28 · 104 阅读 · 0 评论 -
快速配置DataSource
import org.apache.commons.dbcp.BasicDataSource;import org.springframework.jdbc.core.JdbcTemplate; String url = "jdbc:mysql://localhost:3306/cdc_dmap_dev?useUnicode=true&characterEnc...原创 2015-07-02 16:27:25 · 113 阅读 · 0 评论 -
How To Use Spring RESTTemplate To Post Data to a Web Service
使用spring的restelplate的post方法,向web程序发起请求,参数用各种变量,包括@RequestBody。@Controller@RequestMapping("/task")public class TaskWithTokenController extends BaseController { @Autowired private Dat...原创 2015-05-21 16:15:26 · 97 阅读 · 0 评论 -
Sping 执行Quart的Job
这里给出一个Spring执行Quartz的Job的情况:这个支持 Quartz1.x 和 Quartz2.x 的Quartz的版本。public interface Job extends State{ public void execute();}public class InitializeDataSourceMapJob implements Job { pr...原创 2013-12-10 15:03:17 · 114 阅读 · 0 评论 -
SpringMVC使用@ResponseBody输出字符串时遇到的乱码问题及解决办法
来源: http://tchen8.iteye.com/blog/993504来源: http://forum.springsource.org/showthread.php?81858-ResponseBody-and-UTF-8 我的个人解决办法有2个:1、在spring的MVC的范例里面找到了一个解决的方法,就是在使用 @ResponseBody 注释的...原创 2013-07-17 14:55:07 · 163 阅读 · 0 评论 -
spring AOP 常用表达式
Some examples of common pointcut expressions are given below.the execution of any public method:execution(public * *(..))the execution of any method with a name beginning with "set":...原创 2013-07-06 16:48:08 · 180 阅读 · 0 评论 -
spring batch(二):核心部分(1):配置Spring batch
chapter 3、Batch configuration1、spring batch 的命名空间spring xml中指定batch的前缀作为命名空间。示例: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"...原创 2013-01-16 23:52:43 · 706 阅读 · 0 评论 -
spring batch(二):核心部分(2)Spring batch的启动
chapter 4、Running batch jobs 1、Spring Launch API:它的核心就是 JobLauncher 接口。JobLauncher 的接口:public interface JobLauncher { public JobExecution run(Job job, JobParameters jobParameters) throws (…...原创 2013-01-16 23:51:14 · 984 阅读 · 0 评论 -
spring batch(一):基础部分
spring batch官网:http://www.springsource.org/spring-batch下载页面:http://static.springsource.org/spring-batch/downloads.html文档:http://static.springsource.org/spring-batch/reference/index.html...原创 2013-01-16 12:59:27 · 324 阅读 · 0 评论 -
SpringMVC中创建新线程引起的Null错误
今天在一个现有的SpringMVC的Web程序中添加新功能,引起了NullPoint的错误。看了代码,找到了错误的发生点,怎么看,代码都是正确的。不知道为啥?起因是这样的:我在SpringMVC中添加到了controller,然后写了service类。里面涉及了同事的dao类。在service类中的一个查询方法中,调用了2个dao中的查询数据的方法。因为数据量大,为了加快程序的运行速度...原创 2013-11-18 14:54:33 · 293 阅读 · 0 评论 -
spring hornetq selector 过滤消息
在接收 JMS消息的时候,我们经常要在消息队列里面过滤出自己需要的消息,摒弃我们不需要的消息。这个时候就需要用到 JMS的selector功能。这里结合spring3.1,给出一个例子。 发送消息的配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework...原创 2012-12-20 23:31:25 · 125 阅读 · 0 评论 -
spring MVC官网Example的地址
spring MVC官网Example的地址https://github.com/SpringSource/spring-mvc-showcase原创 2013-05-30 09:23:20 · 431 阅读 · 0 评论 -
Spring 集成 HornetQ Topic 应用
用HornetQ和Spring3做了一个简单的小例子,client发送指定的json串,经由HornetQ,由Server接收。 --------------------- client code -----------------------------------spring 配置文件:<?xml version="1.0" encoding="UTF-8"?>...原创 2012-05-31 13:19:07 · 124 阅读 · 0 评论