【Java】Springboot依赖注入顺序问题

【Java】Springboot依赖注入顺序问题

最近初学Springboot,初始化图中SingInRequestProcessor类时,如何让注入的crmProperties不为null?
另外初始化时,会执行方法process内的内容,这是必然的吗?
假如crmProperties不为null,crmProperties.getKeyN()却会为空,初始化时里面还没赋值.

有相关的资料也可以给我推荐一下,谢谢了.

@Component

public class SignInRequestProcessor implements Processor {

@Autowired

private CRMProperties crmProperties;

@Override public void process(Exchange exchange) throws Exception {

//生成工作密钥,需保存

String workKey = DES3Encrpt.newKey(16);

crmProperties.setWorkKey(workKey);

//signInRequest填充参数

SignInRequest signInRequest = new SignInRequest();

signInRequest.setRandom(String.valueOf(KunlunUtils.getRandomInt()));

signInRequest.setClientCode(crmProperties.getClientCode()); //应从配置文件获取

signInRequest.setWorkKey(workKey);

signInRequest.setUserCode(crmProperties.getUserCode());

signInRequest.setPasswd(crmProperties.getPasswd());

signInRequest.setVerifyInfo(crmProperties.getVerifyInfo());

signInRequest.setComputer(crmProperties.getComputer());

signInRequest.setTerminalNo(crmProperties.getTerminalNo());

//XML转换

String signInRequestXML = JAXBUtils.convertObjectToXML(signInRequest);

//RSA加密

String psInputPara = RSAEncrpt.encrypt(signInRequestXML, crmProperties.getKeyE(), crmProperties.getKeyN());

String content = KunlunUtils.generateSoapRequest(12, psInputPara);

exchange.getIn().setBody(content);

}

}

回答

1、简单的方法:CRMProperties类上加上@Component,即可注入。

2、应该不会执行。

3、看CRMProperties中怎么处理赋值了。

以上是 【Java】Springboot依赖注入顺序问题 的全部内容, 来源链接: utcz.com/a/87666.html

回到顶部