Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Debugging Field Injection With NetBeans - Another Reason To Delete Setters

DZone's Guide to

Debugging Field Injection With NetBeans - Another Reason To Delete Setters

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

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

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}