java - spring Propagation.REQUIRES_NEW , nullfies autowired repositories -


i have simple controller method, using propagation=propagation.requires_new feature of spring transaction.

@autowired gzrelimrepository gzrelimrepository;    @autowired relimservice relimservice;  @requestmapping("/startscanning") @transactional(propagation=propagation.requires_new) private void scanresults(@notnull string matchingsrc, @notnull string rangestart, @notnull string rangeend, @notnull integer scanpid){      gzrelimrepository.pscanduppidmwrap(matchingsrc, rangestart, rangeend, scanpid);  } 

when invoke method , gzrelimrepository null , null pointer exception error.

if remove requires_new propogation. things work.

the reason use requires_new that, scanning takes lot of time , want start scanning in own independent new transaction , rest other things in normal existing transaction.

please let me know doing wrong. , approach correct. should try other approach. please suggest.

the problem did not inject gzrelimrepository bean controller.

@autowired relimservice relimservice;  @autowired gzrelimrepository gzrelimrepository;  @requestmapping("/startscanning") @transactional(propagation=propagation.requires_new) private void scanresults(@notnull string matchingsrc, @notnull string rangestart, @notnull string rangeend, @notnull integer scanpid){      gzrelimrepository.pscanduppidmwrap(matchingsrc, rangestart, rangeend, scanpid);  } 

i recommend not use @transactional @ controller level, rather transactions need managed @ service/dao layers.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -