Over a million developers have joined DZone.

Debugging Field Injection With NetBeans - Another Reason To Delete Setters

· Java Zone

Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems, brought to you in partnership with AppDynamics.

Java EE fully supports field injection:

@Stateless
public class LegacyDataSourceConsumer {
@Inject @Legacy
DataSource ds;
}

You can inject resources, EJBs or CDI managed beans directly into fields since Java EE 5 and so for about 5 years. Setters or specific "injector" methods are optional. With NetBeans you can easily debug the injection with a field breakpoint. You only have to click on the grey bar left the editor to enable a field breakpoint. You should see a triangle:

By clicking on the triangle and choosing Field Breakpoint -> Properties you can setup additional behavior. The default behavior "Stop On: Field Access Or Modification" is perfect for Dependency Injection debugging. The current thread will stop (probably in a business method) at injection time. So: delete your setters and enjoy Java EE :-).

From http://www.adam-bien.com/roller/abien/entry/debugging_field_injection_with_netbeans

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}