Below exception handler that is common for all my controllers, is working fine except that I need to disable the WARN log from AbstractHandlerExceptionResolver class after processing the exception. Using Spring Web MVC 5.x version.
#ControllerAdvice
public class AllExceptionHandler{
#ExceptionHandler(SomeCustomException.class)
#ResponseStatus(HttpStatus.BAD_REQUEST)
public void exceptionHandler() {
}
}
This is the log that is generated which I'm trying to avoid:
02-20-2019 15:22:54,896 WARN [http-nio-8080-exec-1] (AbstractHandlerExceptionResolver.java:140) - Resolved [com.rasa.rrt.ste.controller.SomeCustomException]
I'm not using Spring Boot.
Tried to extend the above AllExceptionHandler class with ExceptionHandlerExceptionResolver and call warnLogCategory(null) in the AllExceptionHandler constructor, but it throws NullPointerException.
Also, I see on Google to set this property spring.mvc.log-resolved-exception=false to disable warning, but not sure where/how to set it.
You mentioned spring.mvc.log-resolved-exception=false as a possible solution:
Also, I see on google to set this property "spring.mvc.log-resolved-exception=false" to disable warning, but not sure where/how to set it.
The spring.mvc.log-resolved-exception property is a Spring Boot property, and would be set using standard Spring Boot externalized configuration mechanisms. Enabling the property causes Spring Boot to configure HandlerExceptionResolver beans to log exceptions when they otherwise wouldn't.
Whether to enable warn logging of exceptions resolved by a "HandlerExceptionResolver", except for "DefaultHandlerExceptionResolver".
Since you've stated you're not using Spring Boot, this property is not applicable to your scenario.
You can disable this warning log in your logback configuration,
by specifying in my case in 'logback-spring.groovy' following line
logger("org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver", ERROR)
Related
I am using Couchbase SDK along with Spring boot 2.6.x version. I am using the spring spring-data-couchbase:jar:4.4.0 which in turn has com.couchbase.client:java-client:jar:3.3.0 dependency. The issue, is when trying to execute cluster.query() methods, I need to see what query is getting executed. I need to enable debug logs. However, I have tried configuring it under properties for logging.level for the package com.couchbase.client to DEBUG level, nothing is showing up. I tried the similar config in log4j.xml as well and no luck either. Does couchbase uses any wierd property or is it not reading the properties specified from either log4j or spring's properties?
You may ask if raw query is passed then why log specifically, but this is required if using parameterised queries and to debug it.
How does one enable logging for couchbase if using plain sdk methods under spring's context ?
Can you enable couchbase specific properties of spring-data and not package within the application?
logging:
level:
org.springframework.data.couchbase.repository.query: DEBUG
This should help ! It won't require any external dependency or logging solutions
For the cluster, add ServiceType.QUERY to captureTraffic...
env.ioConfig(it -> it.captureTraffic(ServiceType.QUERY))
and also set the log level for the com.couchbase category to TRACE
I've implemented a basic togglz setup using Spring Boot starter. I'm getting the following at startup:
WARN o.t.s.l.TogglzApplicationContextBinderApplicationListener - ApplicationContext already bound to current context class loader, releasing it first
This may also be causing multiple startups, as I sometimes see the Spring banner go by twice.
To summarize my implementation:
Using property-based toggles in application.yml
Wiring FeatureManager into components
Have a configuration which returns a SpringSecurityUserProvider bean
Not using a TogglzConfig (though I tested with it, and see no difference)
I've looked at the Togglz class, and see the log warning, but I don't understand what situation in Spring Boot would cause this error.
Thank you!
I have been prototyping with Spring boot where I added dependency on spring-boot-starter-actuator and spring-boot-starter-data-rest and named my testing REST endpoint to /info. Application ran without any errors however my endpoint couldn't be called and app returned 404 all the time.
After some time I found out that actuator project contains SAME endpoint /info and basically overrides my custom RESTful endpoint since I didn't name it.
My question is: Is there any way how I can prevent such behavior in general (meaning bean clashing by mistake)? Or at least get WARN message when this is happening.
Thanks in advance for your answers
You can disable /info actuator endpoint by using the following property;
management.endpoint.info.enabled=false
Actually all can be disabled, or you can enable only certain ones, if you check the source link I've provided below;
By default, all endpoints except for shutdown are enabled. If you prefer to specifically “opt-in” endpoint enablement you can use the endpoints.enabled property.
source
For logging of this behaviour, while deploying you can see the endpoints and corresponding beans, you can deduce from this log I guess. But better not to use same endpoint with actuator while they are enabled.
Yes, there is a chance to disable particular classes by #EnableAutoconfiguration with a parameter exclude= where you can specify classname or whole package by using {} brackets
Example:
#EnableAutoConfiguration(exclude = {MyClassName.class}
#EnableAutoConfiguration(exclude = {MyClassName.class, MyClassName2.class})
I've been trying to figure out what I'm missing with my RestTemplate setup (particularly OAuth2RestTemplate) so I want to see the logs for debugging. I found one possible solution for it, but nothing about the operation of the RestTemplate gets shown.
What I've done so far is to replace the default Logback logging mechanism in my Spring Boot app by following the configuration shown here. When I run my Spring Boot application after changing the logging dependencies, all I see on the console is the Spring logo (in ASCII) and nothing else. I've already defined a log4j-spring.properties in src/main/resources with the property defined in the previous link.
What else am I missing here? Do I need to run my Spring Boot app in debug mode? If so, how do I do that? Also, how do I set this up using the default Logback mechanism?
I'm doing and upgrade from Glassfish 3.1.2.2 to Glassfish 4.1 for a set of Spring applications. Since I use the Spring to handle #Inject annotations, I have disabled Glassfish' CDI using this command:
asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi=false
Still, when I deploy one of my applications, I get the following error message:
The lifecycle method [something] must not throw a checked exception.
Related annotation information: annotation [#javax.annotation.PostConstruct()]
on annotated element [public void com.something.MyClass.something() throws
java.io.IOException] of type [METHOD]. Please see server.log for more details.
The class in question is an abstract class with no implementations in the application that I'm trying to deploy, it's just something that is on my classpath.
Why is Glassfish validating my #PostConstruct when I've disabled CDI? Why is Glassfish validating #PostConstruct on something that can not become a bean?
How can I prevent Glassfish from interferring with anything that I'm using Spring for?
Annotation #PostConstruct is a general annotation used in any dependency injection mechanism. The Javadoc explicitely states that, unless used within an interceptor, it must be put on a method, which has void return type and throws no checked exceptions.
It is weird that Spring allows checked exceptions on post-construct methods, as there is not way how to handle them. But as this requirement is only a validation and can be ignored, Spring probably ignores checked exceptions and Glassfish does not. There is possibly an unnecessary Glassfish feature, that it scans and validates all classes, even if not used in CDI or any other mechanism (EJB, ...)
The best is to remove checked exceptions to align the code with the documentation and make it portable.
You can solve this issue first by adding a web.xml with metadata-complete="true". Next you will want to make sure your context are in the Web root Directory /WEB-INF/.
With this glassfish can load all #PostConstructSpring dependencies.
More of a work around in my opinion.