-3

Can I declare a Service injection as static in my Controller?

For example :

@Inject private static UserAttributeService userService;

Update : My requirement was to initialize a Map in static block. The map will be unmodifiable, but it will be initialized after a database call.

But its not being allowed as non static Service layer cannot be called from static block. I havent tried declaring my Service injection as static as I am not sure if its a good practice.

static { crudService.executeNamedQuery(DBOperation.SELECT, "someQuery", null, null); }

javaAndBeyond
  • 520
  • 1
  • 9
  • 26

1 Answers1

0

Yes, you can.

From the annotation's javadoc :

May apply to static as well as instance members.

Aaron
  • 24,009
  • 2
  • 33
  • 57