看我的头像有没有美到窒息的闺蜜头像感

18:46 提问
Spring boot Test 方法启动异常
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.test.web.client.TestRestTemplate] found for dependency [org.springframework.boot.test.web.client.TestRestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
以下是我的test方法
package com.
import org.apache.log4j.L
import org.junit.T
import org.junit.runner.RunW
import org.springframework.beans.factory.annotation.A
import org.springframework.boot.test.context.SpringBootT
import org.springframework.boot.test.web.client.TestRestT
import org.springframework.test.context.junit4.SpringR
@RunWith(SpringRunner.class)
@SpringBootTest(classes=SampleController.class)
public class Test01 {
private Logger log = Logger.getLogger(getClass());
@Autowired
private TestRestTemplate restT
public void contextLoads() {
("in the test method");
this.restTemplate.getForEntity("/", String.class, "Phil");
按赞数排序Spring Boot - Spring Boot,Spring Boot教程,Spring Boot实战 - language - ITeye论坛
Spring Boot
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
发表时间:&&
相关知识库:
Spring Boot QQ交流群:
【Spring Boot 系列博客】
更多查看博客:
跳转论坛:移动开发技术
Web前端技术
Java企业应用
编程语言技术(5)全局异常捕捉【从零开始学Spring Boot】 - 林祥纤 - ITeye技术网站
博客分类:
在一个项目中的异常我们我们都会统一进行处理的,那么如何进行统一进行处理呢?
新建一个类GlobalDefaultExceptionHandler,
在class注解上@ControllerAdvice,
在方法上注解上@ExceptionHandler(value = Exception.class),具体代码如下:
com.kfit.base.exception.GlobalDefaultExceptionHandler
package com.kfit.base.
import javax.servlet.http.HttpServletR
import org.springframework.web.bind.annotation.ControllerA
import org.springframework.web.bind.annotation.ExceptionH
@ControllerAdvice
publicclass GlobalDefaultExceptionHandler {
@ExceptionHandler(value = Exception.class)
publicvoid defaultErrorHandler(HttpServletRequest req, Exception e)
// If the exception is annotated with @ResponseStatus rethrow it and let
// the framework handle it - like the OrderNotFoundException example
// at the start of this post.
// AnnotationUtils is a Spring Framework utility class.
if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null)
// Otherwise setup and send the user to a default error-view.
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", req.getRequestURL());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
//打印异常信息:
e.printStackTrace();
System.out.println("GlobalDefaultExceptionHandler.defaultErrorHandler()");
* 返回json数据或者String数据:
* 那么需要在方法上加上注解:@ResponseBody
* 添加return即可。
* 返回视图:
* 定义一个ModelAndView即可,
* 定义视图文件(比如:error.html,error.ftl,error.jsp);
com.kfit.test.web.DemoController 加入方法:
@RequestMapping("/zeroException")
publicint zeroException(){
return 100/0;
访问: 这个方法肯定是抛出异常的,那么在控制台就可以看到我们全局捕捉的异常信息了
【Spring Boot 系列博客】
更多查看博客:
=========================================================================
您的打赏是我最大的动力,打开微信或者支付宝扫描二维码向我打赏吧: (支付宝支付)
(微信支付)
(410.8 KB)
下载次数: 96
经 测试 @ControllerAdvice& 捕获不到& 全局的异常了。。。不知道是不是版本问题 我用的1.2.7.RELEASE 现在都到1.5+了,建议使用新版本试下。
这个不错 Thank you!
浏览: 677749 次
直接在ftl里面使用${springMacroRequestC ...
@Transactional应该应用哪一个: org.spri ...
修改src中java文件后需要重新编译一下才能生效
6-7下载不了。
大頭蝦 写道缘起缘灭皆有定数,不约来生,只问今生。结缘惜缘了缘 ...

我要回帖

更多关于 美到窒息的闺蜜头像 的文章

 

随机推荐