Reputation: 33
I have class inherit JFrame.
public class MainFrame extends JFrame {
public void init() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setSize(new Dimension(600, 400));
setVisible(true);
setState(Frame.NORMAL);
show();
}
}
Spring config for this bean
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mainFrame" class="todo.ui.MainFrame" init-method="init">
</bean>
</beans>
class JFrame have private field title. Title set from xml config
<bean id="mainFrame" class="todo.ui.MainFrame" init-method="init">
<property name="title">
<value>My To Do List</value>
</property>
</bean>
How to inject private field with annotation?
Upvotes: 1
Views: 669
Reputation: 26572
You have to use @Value annotation:
public class MainFrame extends JFrame {
@Value("my title")
private String title;
or if the value is some dynamic variable then you use:
@Value("#{beanA.title}")
private String title;
Update
If you have to set to the parent then:
@Value("my title")
@Override
public void setTitle(String title){
super.setTitle(title);
}
Upvotes: 1