'How to create java bean configuration from XML for parent bean
I have following XML bean configuration which I need to convert to Java based configuration
<bean id="baseBook" class="com.practice.Book" >
<property name="bookName" value="First book" />
</bean>
<bean id="bookBean" class="com.practice.ChildBook" parent="baseBook">
<property name="bookAuthor" value="Raj" />
<property name="bookPrice" value="200" />
</bean>
Something like below:
@Bean
public ChildBook bookBean(){
ChildBook bookBean = new ChildBook();
bookBean.setBookAuthor("Raj");
bookBean.setBookPrice(200);
return bookBean;
}
@Bean
public Book baseBook(){
Book book = new Book();
book.setBookName("First book");
return book;
}
However, I am not able to set bookName for ChildBook. I checked some solutions which suggests to create new init method and call it in bookBean(). But I am looking for more acurate/convenient solution. Thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
