Injecting configuration items in Java SE 8

Using injection mechanism of Java 8, configuration items can be injected into the application.


public class Config {

@Produces
public int getConfiguration(InjectionPoint ip) {
String cls = ip.getMember().getDeclaringClass().getName();
String fieldName = ip.getMember.getName();
...
get the value of the fieldname from database of file or some other source
...
return value;
}


@Inject
String myConfigItem;

@Inject
int getMyIntConfigItem;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s