setting spring boot logger to debug only for AOP related info - spring-boot

I use the following configuration
logging.level.org.springframework=DEBUG
to investigate in AOP related issues...is there any way to show in the log file only log entries related to AOP the same way as
logging.level.org.springframework.web=DEBUG
but for AOP?

Related

SpringBoot - MDC filter for sl4j

Spring Boot - MDC filter for logging props like correlation-id, http-method with slf4j logs is not working for the been I have created manually whereas it prints the correlation id, http-method in the log that comes out of the class with spring annotation like Component, Service, etc., I really don't understand how that I get the MDC filter to recognise the #Bean instance as well. Thanks and I will appreciate your help!.

Log4j2 on Spring Boot

I've been debugging the whole day and almost tried everything what the internet say about how to do it but I still don't get it correctly.
I am using Spring Boot and log4j2 for my logging because I want my logs to be written on a file instead of console. When I start Spring Boot, the log file is successfully created but I can't see "Hello Philippines" written on the file. I hope you can help me guys with this one.
Here is my Spring Boot Application:
My log4j2.xml
My POM:
I don't have any on my application.properties, this is the result when I run my application:
The name of your logger in the log4j2.xml is com.example but the logger you create in your application is DemoApplication.
You should create your logger like this:
Logger logger = LoggerFactory.getLogger(DemoApplication.class);

Configure data source in spring and mapping in hibernate

Is it possible to configure to DataSource configuration in spring xml and keep the resource mapping in hibernate configuration file.
You can find an example in the Spring reference (http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#orm-hibernate).

How to debug Spring Security authorization annotations?

I have spring security application in which want to enable annotations security (pre and post authorization).
I also have small sample application in which i have implemented it already. Everything works.
But moving configs to main applications failed. There is no errors in console. But annotations do not work. It seems, they are not readed at all.
All configuration and component versions are completely the same.
There are
<security:global-method-security secured-annotations="enabled" />
records in security-context and servlet-context.
But neither #Controller methods no #Service methods are secured with annotation in main application.
How can i debug it?
Solved!
After switch from < global-method-security secured-annotations="enabled" /> to
pre/post annotations works fine.
You can add to your application.yaml:
logging.level.org.springframework.security: DEBUG
Or add to application.properties:
logging.level.org.springframework.security=DEBUG
Or add to your WebSecurityConfig annotation EnableWebSecurity with debug = true:
#Configuration
#EnableWebSecurity(debug = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// ...
}
Set the log level of org.springframework.security to debug. On invoking the method with annotations, you can find log messages that indicate interceptor being applied, especially look for:
DEBUG MethodSecurityInterceptor
Updated:
That means there is some config difference between your sample app and main app
Some pointers to look for:
the <global-method-security> tag needs to be in the same context as your Spring MVC configuration otherwise your controllers will not be post processed. Refer:
http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/faq.html#faq-method-security-in-web-context
you might need pre-post-annotations="enabled", with expressionHandler set.
make sure tag <global-method-security> is in application context
In case you just want to know, which method failed, simply set the logging level for this exception filter:
logging.level.org.springframework.security.web.access.ExceptionTranslationFilter: TRACE
It will only show the stack trace with the failed method and not spam your logs more than necessary ;-)

How to remove NullPointerException from JSR 330 Spring application

I am implementing Spring+JSF application following the guidlines of http://www.mkyong.com/jsf2/jsf-2-0-spring-integration-example/ but I am using the latest Spring version (i.e. 3.x, it already contains the JSR 330 implementation, according to the documentation, so this should not be an issue) and my own classes, that is the difference from the mentioned example.
I am stuck with NullPointerException that indicates that the bean (that acts as JSF managed) bean has not received injection of the instance of Spring bean. All the beans use JSR 330 annotations at appropriate places (#Named, #Inject) and the interfaces of the beans and the variables (under #Inject annotation) follow the usual naming patterns...
So - how to debug this situation. E.g. is there way to see all the beans that sit into the Spring application context. E.g. so we can determine that the Spring context is not initialized appropriately. Maybe there are other methods how to see what is happening in app (debug injection)?
Spring supports JSR 330 annotations for dependency injection provided you have the relevant jars in your classpath.
You need to add the following jar to your application.
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
And you might get good info by enabling logging for org.springframework
Just add log4j jar and drop in this log4j.properties file in the root of the classpath.
Log4j.properties:
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c %M - %m\n
log4j.category.org.springframework=DEBUG
See also:
Documentation
beans-standard-annotations
overview-logging-log4j

Resources