当我通过Jenkins构建jar时,我遇到了一个奇怪的问题。 通过Jenkins创建的WAR文件无法加载" Application.properties"档案。 这意味着它无法在" applicationProperties"中注入任何内容。 " ISellGenevaCacheClient.java"中的字段档案 - LINE 4
如果我在Eclipse中正常构建WAR(通过maven clean install),它可以将值注入" ApplicationProperties" in" ISellGenevaCacheClient.java"档案。
我的" Application.properties"文件存在于src / main / resources
以下是正在使用的java文件。
我的ApplicationProperties.java
@Component
@ConfigurationProperties(locations ="classpath:application.properties", ignoreUnknownFields = false , prefix="prop")
public class ApplicationProperties {
private String algorithm;
public String getAlgorithm() {
return algorithm;
}
void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}
}
EncryptionUtilitiesImpl.java
public class EncryptionUtilitiesImpl {
private ApplicationProperties applicationProperties;
public EncryptionUtilitiesImpl(ApplicationProperties appProp) { // Constructor
applicationProperties = appProp;
}
public String decryptString(final String cipherTextHex) {
byte[] key = formEncryptionKeyArray(applicationProperties.getKeyProp()); // ---> Line 75 : Here , we are getting the applicationProperties as NULL
String decryptString = decryptStringFromHexWithMac(cipherTextHex, key);
return decryptString;
}
}
Utility.java
public class Utility {
public String decryptValue(String encryptedValue){
EncryptionUtilitiesImpl encryptionUtil = new EncryptionUtilitiesImpl(applicationProperties);
return encryptionUtil.decryptString(encryptedValue); // ---> Line 199
}
}
CacheClient.java
public class CacheClient {
@Inject
ApplicationProperties applicationProperties; //. --->. LINE 4
@Inject
Utility utility;
public void init(){
// -- Some code .. . . ..
Utility.decryptValue(applicationProperties.getAlgorithm())) // ---> Line 66
// --- Some code ... . . .
}}
我得到以下NULL指针异常,因为它无法将任何运行时对象注入到' applicationProperties' " CacheClient.java中的字段"档案 - LINE 4。
下面是Stack Trace:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'CacheServiceImpl': Unsatisfied dependency expressed through field 'genevaInstance': Error creating bean with name 'ISellGenevaCacheClient': Invocation of init method failed; nested exception is java.lang.NullPointerException; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CacheClient': Invocation of init method failed; nested exception is java.lang.NullPointerException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CacheClient': Invocation of init method failed; nested exception is java.lang.NullPointerException
Caused by: java.lang.NullPointerException: null
at com.test.util.EncryptionUtilitiesImpl.decryptString(EncryptionUtilitiesImpl.java:75)
at com.test.util.Utility.decryptValue(Utility.java:199)
at com.test.salesinterface.service.integration.geneva.cache.CacheClient.init(CacheClient.java:66)
我真的被困在这里了。请帮助。