4283 shaares
3 results
tagged
springboot
We had an issue with a SpringBoot web app where we had the following error message when querying /manage/beans
Could not write JSON Attempted to serialize java.lang.Class Forgot to register a type adapter?
This was due to org.springframework.boot.actuate.beans.BeansEndpoint.BeanDescriptor having a java.lang.Class<?>
attribute.
We fixed it by configuring our Gson bean this way :
@Bean
public static Gson gson() {
return new GsonBuilder()
...
.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes field) {
return field.getDeclaredType().getTypeName().equals("java.lang.Class<?>");
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();
}
Simply add the following class to your project. It will be automatically registered at start-up if you use the @EnableAutoConfiguration
annotation :
@ControllerAdvice // Makes this the default behaviour of all controllers
@ConditionalOnProperty(prefix = "app", name = "disable-default-exception-handling")
class GlobalControllerExceptionHandler {
@ExceptionHandler(Exception.class) // Catch any exception
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // Returns an error code …
I've lost quite some time on this error recently :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.hibernate.jpa.boot …