John has developed a web application but for unexpected failure he wants to handle Exception in his spring webapplication using ExceptionResolver class. Which one of the following code snippets John will use to configureException bean in spring configuration file? OA OB @Bean public ExceptionResolver resolveException() ExceptionResolver resolver= new ExceptionResolver(): Properties erpProperties= new Properties():erpProperties.setProperty("DataLostException","globalError"):erpProperties.setProperty("BadDataException"error:erpProperties.setProperty("NullPointerException","globalError"):resolversetExceptionMappings(erpProperties): resolver.setDefaultErrorView("404-page"): resolversetExceptionAttribute("exc"): return resolver: @Bean public SimpleMappingExceptionResolver resolveException()SimpleMappingExceptionResolver resolver= new SimpleMappingExceptionResolver():Properties erpProperties= new Properties(): erpProperties.setProperty("DataLostException""globalError"):erpProperties.setProperty("BadDataException""error");erpProperties.setProperty("NullPointerException""globalError"):resolversetExceptionMappings(erpProperties):resolversetDefaultErrorView("404-page"); resolver.setExceptionAttribute("exc"): return resolver @Bean public SimpleMappingExceptionResolver resolveException()SimpleMappingExceptionResolver resolver= new SimpleMappingExceptionResolver()!Properties erpProperties= new Properties(): "globalError")erpProperties.setProperty("DataLostException"erpProperties.setProperty("BadDataException"error erpProperties,setProperty("NullPointerException""globalError"): reso versetException(erpProperties): resolversetDefaultErrorView("404-page"): resolver.setExceptionAttribute("exc"); return resolver! OD none
时间: 2023-07-19 13:40:31 浏览: 49
John should use the following code snippet to configure an Exception bean in the Spring configuration file using `SimpleMappingExceptionResolver`:
```
@Bean
public SimpleMappingExceptionResolver resolveException() {
SimpleMappingExceptionResolver resolver = new SimpleMappingExceptionResolver();
Properties erpProperties = new Properties();
erpProperties.setProperty("DataLostException", "globalError");
erpProperties.setProperty("BadDataException", "error");
erpProperties.setProperty("NullPointerException", "globalError");
resolver.setExceptionMappings(erpProperties);
resolver.setDefaultErrorView("404-page");
resolver.setExceptionAttribute("exc");
return resolver;
}
```
This code snippet creates a `SimpleMappingExceptionResolver` bean and configures it to handle three types of exceptions (`DataLostException`, `BadDataException`, and `NullPointerException`) and map them to corresponding view names (`globalError`, `error`, and `globalError`). It also sets a default error view name to `404-page` and adds an attribute named `exc` to the model for the exception object.