0

We have a system that uses Struts 1 and is Singleton based using enums.

Now we have a dependency that has been written using Spring 4.3.6.RELEASE that was supposed to be used only with other systems that also uses Spring, that's why all Spring dependencies declared have its scope as provided.

Now the system using Struts 1 is supposed to use this dependency. I declared all Spring dependencies necessary, created my application context but unfortunatelly I'm not able to inject beans into my singletons because they are enums.

That dependency does not offer rest services as I requested.

Here's 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's 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 have already read some SO questions such as Inject bean into enum and Using Singleton enum in Spring MVC and have tried the solutions listed in those but didn't get any luck, my enum fields are always null and unfortunatelly those are the only entry point to the dependency.

What can I do to inject the fields?

Community
  • 1
  • 1
Philippe Gioseffi
  • 1,488
  • 3
  • 24
  • 41

0 Answers0