<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all">
</beans>
@ApplicationScoped
public class MyService {
private String state;
public MyService() {
this.state = "initialized";
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
@ApplicationScoped
public class MyBean {
@Inject
private MyService service;
public void doSomething() {
String currentState = service.getState();
service.setState("updated");
}
}