是否可以将Spring Bean注入Enum字段?

时间:2017-03-04 02:18:00

标签: java spring struts-1 java-ee-7

我们有一个使用Struts 1的系统,并且使用枚举基于Singleton。

现在我们已经使用Spring 4.3.6.RELEASE编写了一个依赖项,它应该只与其他使用Spring的系统一起使用,这就是为什么声明的所有Spring依赖项都具有提供的作用域的原因。

现在使用Struts 1的系统应该使用这种依赖。我声明了所有必需的Spring依赖项,创建了我的应用程序上下文但不幸的是我无法将bean注入我的单例中,因为它们是枚举。

我所要求的依赖关系不提供休息服务。

这是我的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>

这是一个演示我问题的课程:

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;
    }
}

我已经阅读了一些问题,比如Inject bean into enumUsing Singleton enum in Spring MVC,并尝试了那些但没有运气的解决方案,我的枚举字段总是空的,不幸的是那些是依赖的唯一入口点。

我可以做些什么来注入这些字段?

0 个答案:

没有答案
相关问题