@ApplicationScoped public class MyService { public void doSomething() { System.out.println("Doing something..."); } } public class MyApp { @Inject private MyService myService; public void run() { myService.doSomething(); } public static void main(String[] args) { Weld weld = new Weld(); WeldContainer container = weld.initialize(); MyApp app = container.select(MyApp.class).get(); app.run(); weld.shutdown(); } } <?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" version="2.0" bean-discovery-mode="annotated"> </beans>


上一篇:
下一篇:
切换中文