We have a system that uses Struts 1 and singletons based on enums.
Now we have a dependency that was written using Spring 4.3.6.RELEASE which should only be used with other systems that also use Spring, so all declared Spring dependencies have their scope as provided.
Now the system using Struts 1 should use this dependency. I have declared all Spring dependencies required, I created my applicationContext, but unfortunately I am not able to inject the beans into my singletons because they are enums.
These dependencies do not offer me any rest services.
Follow my applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
<import resource="classpath:/applicationContext-dependency.xml" />
</beans>
Here is a class that demonstrates my problem:
public enum ItemRemessaUtil {
INSTANCIA;
@Autowired
private BeneficiarioBS beneficiarioBS;
@Autowired
private ItemRemessaBS itemRemessaBS;
@Autowired
public Boleto inserirItemRemessaMultaDesassociacao(final MultaBean multa) throws BOException, DataAccessException {
return this.inserirItemRemessa(multa.getNroFatura(), multa.getNossoNumeroItemRemessa(),
multa.getDataEmissaoBoleto(), multa.getDataVencimentoBoleto(),
multa.getValorFatura().subtract(multa.getValorDesconto()), multa.getComprador(), TipoOrigem.MULTA);
}
@Autowired
public Boleto inserirItemRemessaOrdemCancelamento(final OrdCancelBean ordCancel)
throws BOException, DataAccessException {
return this.inserirItemRemessa(ordCancel.getNrOrdCancel(), ordCancel.getNossoNumeroItemRemessa(),
ordCancel.getDataEmissaoBoleto(), ordCancel.getDataVencimentoBoleto(),
BigDecimal.valueOf(ordCancel.getVlOrdem()), ordCancel.getComprd(), TipoOrigem.CANCELAMENTO_VT);
}
@Autowired
private Boleto inserirItemRemessa(final long numeroPedido, final Long nossoNumeroItemRemessa,
final Date dataDocumento, final Date dataVencimentoBoleto, final BigDecimal valorTotal,
final ComprdBean comprdBean, final TipoOrigem tipoOrigem) throws BOException, DataAccessException {
final Boleto boleto = BoletoBancarioFactory.criarBoletoSantander(
this.beneficiarioBS.construirBeneficiario(tipoOrigem, ConstantesBoleto.CNPJ_RIOPAR, numeroPedido,
nossoNumeroItemRemessa, dataVencimentoBoleto),
BoletoUtil.construirPagador(comprdBean),
Datas.novasDatas(dataDocumento,
TipoOrigem.MULTA.equals(tipoOrigem)
? ParamMultaDesassociacaoBO.retornarQuantidadeDiasVencimentoMultaDesassociacao()
: ConstantesBoleto.QUANTIDADE_DIAS_VENCIMENTO_BOLETO_SANTANDER),
valorTotal);
if (nossoNumeroItemRemessa == null
|| DateUtil.retornarDataSemHorario(dataVencimentoBoleto).before(boleto.getDatas().getVencimento())) {
this.itemRemessaBS.inserirItemRemessa(boleto);
}
return boleto;
}
}
I've read some of the questions in the American OS as Inject bean into enum and Using Singleton enum in Spring MVC and tried the listed solutions, but my enum attributes never are injected and, unfortunately, only through them I can enter the dependency.
What can I do to inject the dependencies of these attributes?