Java EE xml bean

时间:2013-03-05 14:06:24

标签: spring java-ee-6

是否可以像在Spring中通过XML配置文件一样在Java EE中定义bean。

在春天我可以拿一个POJO

public class ClickCounter {

private int count;  
public int getCount() {return count;}  
public void setCount(int count) {this.count = count;}

}

并在xml中定义bean

<bean id="clickCounter" class="com.clickcounter.ClickCounter">
</bean>

1 个答案:

答案 0 :(得分:0)

只需创建一个空的beans.xml,如:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
        http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

然后创建你的bean:

import javax.ejb.Singleton;
@Singleton
public class MyBean{
}