i using spring boot , want cache data here entity , repository classes
places entity class:
@entity @table(name = "place_master") @getter @setter @noargsconstructor @equalsandhashcode(callsuper = true) @component public class placemaster extends baseentity{ @id @generatedvalue(strategy = generationtype.identity) @column(name = "place_master_id") @jsonview(view.place.class) private long placemasterid; @column(name = "place_name") @jsonview(view.place.class) private string placename; @column(name = "alt_place_name") private string alternateplacename; @column(name = "pincode") private string pincode; @column(name="district_name") private string districtname; @manytoone (cascade = cascadetype.all) @joincolumn(name = "state_master_id") private statemaster statemaster; }
state entity class:
@entity @table(name = "state_master") @getter @setter @noargsconstructor @equalsandhashcode(callsuper = true) //@tostring public class statemaster extends baseentity { @id @generatedvalue(strategy = generationtype.identity) @column(name = "state_master_id") private long statemasterid; @column(name = "state_name") private string statename; @column(name = "state_code") private string statecode; @onetomany(mappedby = "statemaster", cascade = cascadetype.all) private list<placemaster> placemaster = new arraylist<placemaster>(); } public interface placemasterrepository extends jparepository<placemaster, long> { @override @cacheable("places") public list<placemaster> findall(); }
bootstrap application class:
@springbootapplication @enablecaching @enableasync @enabletransactionmanagement public class myapplication { @autowired private placemasterrepository placemasterrepository; public static void main(string[] args) throws throwable { springapplication.run(goyaanaapplication.class, args); } }
when run the spring boot application getting below error. due biderectional dependency. please help
caused by: org.springframework.beans.factory.beancurrentlyincreationexception: error creating bean name 'entitymanagerfactory': requested bean in creation: there unresolvable circular reference? @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.beforesingletoncreation(defaultsingletonbeanregistry.java:347) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvereference(beandefinitionvalueresolver.java:351)
it best avoid circular dependencies between bean, e.g. moving @enablecaching
, @enableasync
, @enabletransactionmanagement
separate @configuration class.
in cases not possible, can around adding @lazy annotation on @autowired bean. create lazy proxy resolved @ runtime. comes caveat - can't sure @ start of application if wired correctly.
@lazy @autowired private placemasterrepository placemasterrepository;
for details see spring documentation.
Comments
Post a Comment