Let's take a look at the implementation of EJB3 's SLSB:
import javax.ejb.Stateless;
@Stateless
public class HelloBean{
private String _greeting = "Default Hello";
public void setGreeting(String greeting)
{
_greeting = greeting;
}
public String hello()
{
return _greeting;
}
}
然后我们看看xml中的配置方法:
<ejb-server>
<bean type="...">
<init greeting="Hello, world"/>
</bean>
</ejb-server>
What do we see? In the configuration file, "Hello, World" is passed to setgreeting as a parameter, of course, the EJB implementation generates the Hello interface based on the default value, and the interface's method implementation directly calls return _greeting; Hello, World. "
The set method is used to pass the required string to setgreeting, and if our requirements change, we only need to make changes in the configuration file, which is what the IOC model
Type2.
Visible, EJB3 use of the IOC model and spring adopted by the IOC, have adopted a type2 approach, learning Spring, for us to learn EJB3 is also a good foreshadowing.