vendredi 27 février 2015

How to create just one instance of session spring bean

I Have a Rest webservices that invokes methods implemented in a session scoped spring service.



@Path("/ama04")
@Service("ama04")
@PerSession
public class Ama_04Service implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/

@Autowired
Ama_04WebService ama_04WebService;

@GET
@Path("/quest/{date}/{numDonn}/{language}")
@Produces("application/json; charset=UTF-8")
public String verifNum(@PathParam("numDonn") final String numDonn,
@PathParam("date") final String date,
@PathParam("language") final String language) {

return ama_04WebService.verifNum(numDonn, date, language);

}



@GET
@Path("/clickRepons/{numDonn}/{occRep}/{occ}/{date}/{language}")
@Produces("application/json; charset=UTF-8")
public String clickReponse(@PathParam("numDonn") final String numDonn,
@PathParam("occRep") int occRep, @PathParam("occ") int occ,
@PathParam("date") final String date,
@PathParam("language") final String language) {

return ama_04WebService.clickReponse(numDonn, occRep, occ, date,
language);
}


And this is the spring bean:



@Service("ama04Service")
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
@Transactional(readOnly = false)
public class Ama04ServiceImpl implements Ama04Service, LineListener {

private List<Map<String, String>> dummyRepList;
private List<Map<String, String>> listDummyRep;

private List<Map<String, Object>> antmMapList = new ArrayList<Map<String, Object>>();
private List<Map<String, Object>> entdonnci = new ArrayList<Map<String, Object>>();
private List<Map<String, Object>> entcids = new ArrayList<Map<String, Object>>();
private List<Map<String, Object>> entcidsd = new ArrayList<Map<String, Object>>();

private Map<String, String> dummyRep;
private Map<String, String> dudossmedC;
private Map<String, String> ligne = new LinkedHashMap<String, String>();
private Map<String, String> params = new HashMap<String, String>();
private Map<String, String> cles = new HashMap<String, String>();
private Map<String, Object> cidsMap = new HashMap<String, Object>();


The problem is in the second method call spring re instantiate the Ama_04Webservice so the values charged in the first call will be lost. How can save the satuts of my global vars in the second call? I mean how can i create only one instance the ama04Service (As how Singleton work) but without changing it's scope to ama04Service @Scope(value="singleton") instead of @Scope(value="session")


Aucun commentaire:

Enregistrer un commentaire