Spring Boot 앱에서 예외를 처리하려고 할 때 로그에 ErrorPageFilter 오류가 발생했습니다.
작은 Spring Boot 응용 프로그램을 만들었고 이제 나만의 예외 처리를 추가하려고 합니다.앱이 예상대로 작동하는데도 로그에 오류가 발생하는 문제가 있습니다.구성:
- Tomcat 8(독립 실행형)
- 스프링 부트 버전 1.2.3
- 전쟁 포장
예외 처리기는 다음과 같습니다.
@ControllerAdvice
public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
@ResponseBody ErrorInfo handleNotFoundRequest(HttpServletRequest req, Exception ex) {
return new ErrorInfo(req.getRequestURL().toString(), ex);
}
}
예외를 발생시키는 내 컨트롤러:
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = {"application/json"})
public @ResponseBody
HashMap environment(@PathVariable("id") long id) {
HashMap<String, Object> map = new HashMap();
Environment env = environmentService.getEnvironment(id);
if(env == null) throw new NotFoundException("Environment not found: " + id);
map.put("environment", env);
return map;
}
내 Spring Boot 응용 프로그램 설정:
@SpringBootApplication
@EnableAutoConfiguration(exclude=ErrorMvcAutoConfiguration.class)
@ComponentScan
public class QaApiApplication {
public static void main(String[] args) {
SpringApplication.run(QaApiApplication.class, args);
}
}
서블릿 이니셜라이저:
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(QaApiApplication.class);
}
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
......
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
예외를 생성하는 통화를 하면 404에 JSON이 예상됩니다.그러나 로그에 ErrorPageFilter 오류가 표시됩니다.
2015-04-09 21:05:38.647 오류 85940 --- [io-8080-exec-16] os.boot.context.web.ErrorPageFilter: 응답이 이미 커밋되었으므로 요청 [/environments/1]에 대한 오류 페이지로 전달할 수 없습니다.결과적으로 응답에 잘못된 상태 코드가 있을 수 있습니다.응용 프로그램이 WebSphere Application Server에서 실행 중인 경우 com.ibm.ws 을 설정하여 이 문제를 해결할 수 있습니다.웹 컨테이너.vmdk서비스 후 false로 플러시
시작/배포에 오류가 없고 제가 볼 때는 모든 것이 작동하는 것 같습니다.제가 정확하게 재정의하지 않은 기본 동작이 있는 것 같습니다만, 정확히 무엇인지는 아직 파악하지 못했습니다.
이와 관련된 어떠한 도움이나 팁도 매우 감사할 것입니다. 저는 문제가 무엇인지에 대해 막막해졌기 때문입니다.
여전히 Spring-boot 버전 1.4.2가 아닌 1.2.3을 사용하는 경우.솔루션이 제공된 경우 릴리스)한 후 확장SpringBootServletInitializer및 재정의 방법run다음과 같이:
@SpringBootApplication
@EnableAutoConfiguration(exclude=ErrorMvcAutoConfiguration.class)
@ComponentScan
public class QaApiApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(QaApiApplication.class, args);
}
@Override
protected WebApplicationContext run(SpringApplication application) {
application.getSources().remove(ErrorPageFilter.class);
return super.run(application);
}
}
저한테는 효과가 있어요.
저는 WAS Liberty 프로필에서 실행되는 Springboot 2.0 앱과 같은 문제로 끝났습니다.속성 파일에서 아래 구성으로 오류 페이지 필터링을 비활성화했습니다.logging.level.org.springframework.boot.context.web.ErrorPageFilter=off
언급URL : https://stackoverflow.com/questions/29547233/errorpagefilter-error-in-log-when-trying-to-handle-exception-in-a-spring-boot-ap
'programing' 카테고리의 다른 글
| Pandas DataFrame의 행 인덱스 값을 목록으로 가져오시겠습니까? (0) | 2023.08.10 |
|---|---|
| powershell의 읽기-호스트 기능을 사용하여 외부 서비스의 암호를 수락하려면 어떻게 해야 합니까? (0) | 2023.08.10 |
| Oracle JDBC 드라이버에서 타임스탬프 열에 Java 날짜를 쓸 때 시간대는 어떻게 됩니까? (0) | 2023.08.10 |
| ORACLE에서 CTE 및 테이블 업데이트 (0) | 2023.08.10 |
| MutableLiveData에서 setValue()와 postValue()의 차이 (0) | 2023.08.10 |