first of all. Using ControllerAdvice alone does not work properly. Need to cooperate with @EnableWebMvc.
@ControllerAdvice
@EnableWebMvc
pulbic class ExceptionControllerAdvice{
@ExceptionHandler(NotFoundException.class)
@ResponseBody
public Map<String,Object> notFoundExc(NotFoundException exc,HttpServletRequest req){
…….
}
}
An error is reported during the startup of exception handling.
Error message:
Jul 04, 2016 11:00:11 AM org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver doResolveHandlerMethodException
Warning: Failed to invoke @ExceptionHandler method: public java.util.Map<java.lang.String, java.lang.Object> com.dooioo.modelException.ExceptionControllerAdvice.notFoundError(com.dooioo.modelException.NotFoundException,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:134)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:101)
at ……….. (omitted…)
The messageconverter processor has been configured in xx-servlet.xml.
<bean id=“dyMessageConverter” class=“com.dooioo.web.converter.DyMappingJacksonHttpMessageConverter”/>
<bean class=“org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter”>
<!– Processing function for spring binding –>
<property name=“webBindingInitializer”>
<bean class=“com.dooioo.init.DefaultBindingInitializer”/>
</property>
<property name=“messageConverters”>
<list>
<bean class=“org.springframework.http.converter.ByteArrayHttpMessageConverter”/>
<ref bean=“dyMessageConverter”/>
</list>
</property>
<property name=“requireSession” value=“false”/>
<property name=“order” value=“0”/>
</bean>
Going through the information online to no avail.
Finally, it is found that there is a relationship with the order in the xml. <mvc:annotation-driven />.
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter adapter must be declared before <mvc:annotation-driven />, otherwise the conversion of parameter types cannot be processed normally
This problem is solved.
Read More:
- JZVideo Error: Attempt to invoke virtual method ‘android.view.Window android.app.Activity.getWindow()’ on a null object reference
- [Solved] Response Export error on submit request on future invoke, java.lang.OutOfMemoryError: Java heap space
- The showdialog() method in thread/threading. Timer/task reported an error: “before ole can be called, the current thread must be set to single thread unit (STA) mode.”
- Springboot integrates redis factory method ‘redisconnectionfactory’ threw exception; nested exception is
- [Solved] conda activates the virtual environment error: Invoke-Expression
- Solutions to error reporting after adding comments to XML files
- Error reported when springboot connects to redis nested exception is redis.clients.jedis . exceptions.JedisConnectionException
- Yaml is installed, and the error YAMLLoadWarning is reported as soon as the code runs: calling yaml.load() without Loader=… is deprecated, as the default Loader is unsafe.
- Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen is reported when docker port mapping or starting the container
- The SDK of Android webrtc compiled with Ninja – C out / release command reported an error, and the Android NDK processing method could not be found
- VUE: Property or method “deleteFun“ is not defined on the instance but referenced during render. [How to Fix]
- The method println(boolean) in the type PrintStream is not applicable for the arguments (void) Error
- How to Solve platformio adding library error
- Zeppelin reported an error. The JDK version is low
- Error husky > pre-commit (node v10.16.3) is reported when git commit is submitted
- About completionfailedexception: error reported by compilation failed to complete
- Aspecj cannot intercept method annotations on an interface
- POI Export Excel Error: HTTP Status 500 – Request processing failed; nested exception is java.lang.NullPointerException
- Fetch Error: Failed to execute ‘fetch’ on ‘Window’: Request with GET/HEAD method cannot have body