简体   繁体   中英

Spring java config to invoke a public non static method of a singleton class with private constructor

I am working on changing a spring project to springboot and changing to java config from xml. I have a singleton class with a private constructor, in the original xml the non static methods are invoked as such:

<bean id="myClassBeanId" class="com.myproject.dao.MyClass">

<bean id="daoservice" factory-bean="myClassBeanId" factory-method="createMyStaticVariable">

The objective is to somehow invoke the "public non static method" of a class with a private constructor to initialize the static variables of the same class in spring java config. Could someone please tell the java config equivalent of the above xml config.

@Bean
public MyClass myClass() {
MyClass.class.getConstructror().makeAccessable () ;
return MyClass.class.getConstructror().invoke() :
} 
@Bean
public DaoService daoService(MyClass myClassBeanId) {
return myClassBeanId.createMyStaticVariable():
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM