I have a spring boot application wherein there is an aspect which logs method names and arguements.
@Component
@Aspect
public class LoggingAspect {
@Autowired
private ParameterNameDiscoverer parameterNameDiscoverer;
private static final Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
@Pointcut("within(@org.springframework.stereotype.Service *)")
public void beanAnnotatedWithServiceOrASpecializationOfIt() {}
...
...
}
But when I deploy the application it says
Could not autowire field: private org.springframework.core.ParameterNameDiscoverer
Following is a part of pom.xml file that is being used
<properties>
<java.version>1.8</java.version>
<start-class>SampleApplication</start-class>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.M5</version>
</parent>
I want to log the method arguement names and their values as an aspect. I am getting the method arguement values but not their names.
Assuming you are using java config, you need to make sure you have a class annotated somewhere in your code with an @Configuration
and something like this:
@Bean
public ParameterNameDiscoverer parameterNameDiscoverer() {
return new DefaultParameterNameDiscoverer();
}
Note: there may be a more appropriate implementation of ParameterNameDiscoverer
for your particular use case, you should check the spring documentation for details.
Do you actually have a ParameterNameDiscoverer in the spring context? If you expect this to be created as a part of the spring boot auto configuration, you will be able to see it mentioned in the auto configuration logs that are spat out by Boot on startup.
It might be you have to configure your own ParameterNameDiscoverer as a Bean, or add an extra classpath dependency in order for spring boot to create you one during auto configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With