Hello Friends, If you Want to call the method after your bean is initialize in spring you can use the following options.
Use the afterProprtiesSet method.
class MyClass implements InitializingBean {
public void afterPropertiesSet() throws Exception {
System.out.println("my bean is initialized");
}
}
2:- You can use the annotation @PostConstruct in your class. to enable this you need to define in your application context xml file.
class MyClass implements InitializingBean {
@PostConstruct
public void initMethod() throws Exception {
System.out.println("my bean is ready");
}
}
3:- You can also use the init method attribute in your application context xml file.
<bean id="myclass" class="com.MyClass" init-method="initMethod">
</bean>
and make the function name initMethod in your MyClass.java file
package com;
class MyClass {
public void initMethod() throws Exception {
System.out.println("my bean is ready");
}
}
0 Comment(s)