我想做什么?
- 为了测试,我想为我的应用程序设置serverKey
并validity
希望货物注入到 TokenUtils,所以这些值在应用程序加载时可用
我试过什么?
我JBoss
用作容器,相关代码是
@Stateless
public class TokenUtils {
public static final String AUTH_TOKEN = "X-BB-AUTH";
public static final String BB_AUTH_PRIVATE_KEY = "auth.key";
public static final String BB_AUTH_VALIDITY = "auth.validity";
private static final Pattern PATTERN = Pattern.compile(":");
private String serverPrivateKey;
private long validity;
private static final Logger LOGGER = LoggerFactory.getLogger(TokenUtils.class);
@SuppressWarnings("UnusedDeclaration")
public TokenUtils() {
}
public TokenUtils(@Nonnull @Configuration(BB_AUTH_PRIVATE_KEY) final String serverPrivateKey,
@Configuration(BB_AUTH_VALIDITY) final long validity) {
this.serverPrivateKey = serverPrivateKey;
this.validity = validity;
LOGGER.info("serverPrivateKey:" + serverPrivateKey);
LOGGER.info("validity:" + validity);
}
}
另外,我META-INF/beans.xml
在创建src/main/resources
的同一个包中TokenUtils
,所以我猜bean实例化不是问题
我希望在 cargo 实例化 bean 时注入值,所以我将值设置pom.xml
为
<container>
<systemProperties>
<auth.key>secure</auth.key>
<auth.validity>720000</auth.validity>
</systemProperties>
</container>
当我开始货运时,我看到以下情况发生
INFO] [talledLocalContainer] 06:07:08,068 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named TokenUtils in deployment unit deployment "market.war" are as follows:
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] java:global/market/TokenUtils!com.org.proj.service.authentication.TokenUtils
[INFO] [talledLocalContainer] java:app/market/TokenUtils!com.com.proj.service.authentication.TokenUtils
[INFO] [talledLocalContainer] java:module/TokenUtils!com.com.proj.service.authentication.TokenUtils
[INFO] [talledLocalContainer] java:global/market/TokenUtils
[INFO] [talledLocalContainer] java:app/market/TokenUtils
[INFO] [talledLocalContainer] java:module/TokenUtils
问题?
- 但是值是serverPrivateKey=null
和validity=0
- 此外,在 bean 实例化期间,我应该能够看到LOGGER.info
值,但我无法在日志中找到它们
我做错了什么?