public interface LogService {
void writeLog(String message);
}
@ApplicationScoped
public class LogServiceImpl implements LogService {
public void writeLog(String message) {
System.out.println(message);
}
}
public class LogServiceActivator implements BundleActivator {
private ServiceRegistration<LogService> registration;
public void start(BundleContext bundleContext) {
LogService logService = new LogServiceImpl();
registration = bundleContext.registerService(LogService.class, logService, null);
}
public void stop(BundleContext bundleContext) {
registration.unregister();
}
}
<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.1.xsd"
bean-discovery-mode="all">
<decorators><class>org.jboss.weld.decorator.bean.GenericDecorator</class></decorators>
<interceptors><class>org.jboss.weld.interceptor.util.proxyTargetLocator</class></interceptors>
</beans>
@Inject
private LogService logService;
logService.writeLog("Hello, World!");