最近,在项目开发过程中使用了RedisTemplate,进行单元测试时提示“Field redisTemplate in com.example.demo1.dao.RedisDao required a bean of type ‘org.springframework.data.redis.core.RedisTemplate’ that could not be found”,翻译过来就是“找不到类型为RedisTemplate的bean”.当然,仅看这句话我们无法确定为什么会出现这个问题…
  WIN7中 HttpListener 拒绝访问 异常解决 C# http://www.cnblogs.com/cmdszh/archive/2012/08/16/httplistener.html   在项目中使用HttpListener为本地的Flex提供了一个图片传输的功能 注册地址:http://+:9527/icon 运行生产的程序出现: ----------------------------------- UnHandledException Message:拒绝访问 在Syst…
静态属性不能直接注入,可以通过其set方法进行注入.(注意生成的set方法需要去掉static). 在工具类里直接注入RedisTemplate,两种方法: (1)使用@Autowired private static RedisTemplate redisTemplate; @Autowired public void setRedisTemplate(RedisTemplate redisTemplate) { JwtUtil.redisTemplate = redisTemplate; }…
RESTFul Service中如果要注入EJB实例,常规的@Inject将不起作用,在Jboss中,应用甚至都启动不起来(因为@Inject注入失败),解决方法很简单:将@Inject换成@EJB 参考代码: CityInvoker是一个Stateless的EJB package test; import javax.ejb.Stateless; import ... @Stateless public class CityInvoker { public CityResponse getCi…
springboot中抛出异常,springboot自带的是springmvc框架,这个就不多说了. springmvc统一异常解决方法这里要说明的是.只是结合了springboot的使用而已.直接上代码,有效有用的才是ok. 1.定义异常捕获 package com.example.rest.error; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.Exce…
在Spring项目中,有时需要新开线程完成一些复杂任务,而线程中可能需要注入一些服务.而通过Spring注入来管理和使用服务是较为合理的方式.但是若直接在Thread子类中通过注解方式注入Bean是无效的. 因为Spring本身默认Bean为单例模式构建,同时是非线程安全的,因此禁止了在Thread子类中的注入行为,因此在Thread中直接注入的bean是null的,会发生空指针错误. 以下分别列举错误的注入方法和两种解决方式. 错误的注入方法 @Controller public class…
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcache' defined in class path resource [applicationContext-ehcache.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheExc…
一.背景 在我们在编写程序的过程中,无法保证自己的代码不抛出异常.当我们抛出异常的时候,通常会将整个异常堆栈的信息使用日志记录下来.通常一整个异常堆栈的信息是比较多的,而且存在一些没用的信息.那么我们如何优化一些异常堆栈的信息打印,过滤掉不必要的信息呢? 二.需求 1.现有的异常堆栈信息 2.我们想优化成如下 三.使用的技术 1.此处我们是在SpringBoot中使用logback来实现日志的打印. 2.默认情况下,重写异常堆栈的打印比较复杂,此处我们采用第三方实现 ogstash-logbac…
报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.redis.core.RedisTemplate<java.io.Serializable, java.io.Serializable>' available: expected at least 1 bean which qual…
直接注入(Autowired) @Configuration public class OAConfig { @Autowired private ApplicationContext applicationContext; @Bean public PersonUtils personUtil(){ boolean bool=applicationContext.containsBean("aa"); System.out.println("containsBean:aa:…