java - How to create a MAP that has an application scope? And Where to declare it? -
i need create map has application scope. , so, if user1 add map object using method1 of class1, user2 find new objects using method2 of class2.
i know there annotation :
@applicationscoped
but, don't know map should declared or used, make have same state @ anytime , anywhere in application deployment time.
an example representing class map declared , method of class using it, helpful.
declare cdi bean provide map
consumption:
@named @applicationscoped public class applicationscopedbean { private map<keyclass, valueclass> map; @postconstruct public void init() { //initialize map , data here map = new concurrenthashmap<>(); map.put(..., ...); //... } //provide getter map public map<keyclass, valueclass> getmap() { return this.map; } }
now, bean can injected in clients , can show data in view.
Comments
Post a Comment