我配置了一个具有一些初始化逻辑的 bean。我已经使用 @ApplicationScoped 注释对这个 bean 进行了注释。但不知何故,cdi 没有选择这个 bean。
beans.xml 内容:
<?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_1_1.xsd"
bean-discovery-mode="annotated">
</beans>
豆文件:
@ApplicationScoped
public class Initializer{
@Inject @ConfigProperty(name = "app.name")
private String appName;
@Inject @ConfigProperty(name = "app.token")
private String appToken;
@Inject @ConfigProperty(name = "app.version")
private String appVersion;
@PostConstruct
public void init() {
System.out.println("flow should come here....); //but this line does not execute.
}
}
读取配置文件的代码:
@Exclude
public class ConfigurationFile implements PropertyFileConfig {
@Override
public String getPropertyFileName() {
String env = Util.getEnv();
switch (env) {
case "dev":
case "uat":
case "prod":
return "config/" + env + "/default.properties";
default:
return "config/default.properties";
}
}
@Override
public boolean isOptional() {
return false;
}
}
我正在使用:cdiL:用于依赖注入,apache-deltaspike:用于读取配置文件。野蝇群:服务器