抽象
这是在Java SE应用程序中引导CDI 2.0的快速参考。
CDI 2.0(JSR 365)
Maven依赖
<dependency><groupId>org.jboss.weld.se</groupId><artifactId>weld-se-core</artifactId><version>3.0.2.Final</version>
</dependency>
beans.xml
文件位置是/META-INF/beans.xml
。 这个文件是可选的,尽管我发现它仍然很不错。
<beans version="2.0" 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"
><scan><exclude name="org.jboss.weld.**" /></scan>
</beans>
Java SE应用程序
package org.ferris.cdi.example.main;import javax.enterprise.inject.se.SeContainer;
import javax.enterprise.inject.se.SeContainerInitializer;/*** The main() method for this application** @author <a href="mailto:mjremijan@yahoo.com">Mike Remijan</a>*/
public class Main {public static void main(String[] args) {SeContainer container= SeContainerInitializer.newInstance().initialize();Main main= container.select(Main.class).get();//. . .}
}
摘要
就是这样...享受!
翻译自: https://www.javacodegeeks.com/2018/01/bootstrap-cdi-2-0-java-se.html