Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Spring: override parent bean

Is it possible to override/replace parent abstract bean?

E.G: 1st xml:

<bean id="inheritedTestBean" abstract="true" class="org.springframework.beans.TestBean">
</bean>

<bean id="inheritsWithDifferentClass" class="org.springframework.beans.DerivedTestBean" parent="inheritedTestBean">
</bean>

2nd xml

<bean id="inheritedTestBean2" abstract="true" class="org.springframework.beans.TestBean2">
</bean>
<alias name="inheritedTestBean2" alias="inheritedTestBean" />

TestBean2 inherits TestBean.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Any given Spring context can only have one bean for any given id or name. In the case of the XML id attribute, this is enforced by the schema validation. In the case of the name attribute, this is enforced by Spring's logic.

However, if a context is constructed from two different XML descriptor files, and an id is used by both files, then one will "override" the other. The exact behaviour depends on the ordering of the files when they get loaded by the context.

So while it's possible, it's not recommended. It's error-prone and fragile, and you'll get no help from Spring if you change the ID of one but not the other.

about 4 years ago · Santiago Trujillo Relatório

0

Even if you could do this, it would be very confusing. There is the @Primary annotation, you can take a look at that. Or you could take a look at spring profiles, so you have a default bean implementation, and then every other profile there is a different implementation for your abstract class.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda