-
Notifications
You must be signed in to change notification settings - Fork 33
Spring3
The Spring 3 module provides the following features:
- A way to inject the request tracer into any Spring bean
- Support for the @Traced annotation as a way to incorporate tracing into your Spring beans
Add a dependency as follows for maven:
<dependency>
<groupId>com.comcast.money</groupId>
<artifactId>money-spring3</artifactId>
<version>${money.version}</version>
</dependency>
And here is a dependency for SBT:
libraryDependencies += "com.comcast.money" %% "money-spring3" % "${money.version}"
You need to configure a few beans in order for Money to magically start happening.
- You need to configure the
DefaultAdvisorAutoProxyCreator
. This bean applies advice to any Spring bean method using the@Traced
annotation - You need to add money to auto wiring Component scan.
Here is a sample Annotation config:
@Configuration
@ComponentScan(basePackages = {"com.comcast.money.samples.springmvc", "com.comcast.money.spring3"})
public class AppConfig {
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
final DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
return defaultAdvisorAutoProxyCreator;
}
}
The @Traced annotation is the most useful feature in order to instrument your spring application.
To use it, simply add the annotation to any public method on a Spring managed bean:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.comcast.money.annotations.Traced;
import static com.comcast.money.japi.JMoney.*;
@Component
public class SampleTraceBean {
@Traced("SampleTrace")
public void doSomethingGood() {
record("something", "good")
}
}
In the example, we auto-wire our SampleTraceBean
class by using the @Component annotation. We start and stop a trace span around the doSomethingGood
method by using the @Traced annotation.
Here, we can use the methods on the [Money Java API](https://github.comcast.com/aae/money/wiki/Money In Java) to record notes.
Sometimes, you may want to test using mocks, or just generally prefer using dependency injection for everything; we got you covered here.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.comcast.money.annotations.Traced;
@Component
public class SampleTraceBean {
@Autowired
private SpringTracer springTracer;
@Traced("SampleTrace")
public void doSomethingGood() {
springTracer.record("foo", "bar");
}
}
The example above is the exact same thing as the previous example, except we are using the SpringTracer
instead of the Money API directly.
- Overview
- Configuration
- Logging Setup
- Performance Considerations
- Java Users Guide
- Scala Users Guide
- Modules
- Contributing