我正在尝试在java SE中设置一个非常简单的焊接实现.
我有扩展类:
public class MyExtension implements Extension {
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) {
System.out.println("Starting scan...");
}
<T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> annotatedType, BeanManager beanManager) {
System.out.println("Scanning type: " + annotatedType.getAnnotatedType().getJavaClass().getName());
}
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd) {
System.out.println("Finished the scanning process");
}
public void main(@Observes ContainerInitialized event) {
System.out.println("Starting application");
new Test();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个我想要注入的简单类:
public class SimpleClass {
public void doSomething() {
System.out.println("Consider it done");
}
}
Run Code Online (Sandbox Code Playgroud)
最后我要把它注入的课程:
public class Test {
@Inject
private SimpleClass simple;
@PostConstruct
public void initialize() …Run Code Online (Sandbox Code Playgroud)