How does annotation injection work, while maintaining security?

D

Danno

How do frameworks inject a resource into a private field without
violating security?

I know how to introspect, and I know how to get annotations, etc. I
just would like to know how to inject something into a private field
for testing purposes.
 
D

Danno

How do frameworks inject a resource into a private field without
violating security?

I know how to introspect, and I know how to get annotations, etc. I
just would like to know how to inject something into a private field
for testing purposes.

Another term is "field injection". Most searches are about how to
use. I am looking at how to implement.
 
D

Danno

How do frameworks inject a resource into a private field without
violating security?

I know how to introspect, and I know how to get annotations, etc. I
just would like to know how to inject something into a private field
for testing purposes.

Alright I got it....It is a simple case of called setAccessible on a
field in order for that to work.

Field field = t.getClass().getDeclaredField("someField");
field.setAccessible(true);
field.set(t, "woo");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top