Override Component doesn't work

@codrinl hi! You can create your own Metadata implementation and override default implementation by the @Primary annotation ([Spring Docs](Core Technologies)) or by overriding it in the spring.xml file:

<bean id="cuba_Metadata"
class="com.company.app.core.sys.MyMetadataImpl"/>

@prozac631 I tried both and none of them works…

  1. Primary annotation approach:
@Component(Metadata.NAME)
@Primary
public class ScopeMetadataImpl implements Metadata 
  1. append web\src\web-spring.xml file or core\src\spring.xml file
    <bean id="cuba_Metadata" class="com.company.scope.service.ScopeMetadataImpl"/>

same error for both approaches

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'cuba_Metadata' for bean class &#91;com.company.scope.core.sys.ScopeMetadataImpl&#93; conflicts with existing, non-compatible bean definition of same name and class &#91;com.haulmont.cuba.core.sys.MetadataImpl&#93;

I also changed the namespace to com.company.scope.core.sys.ScopeMetadataImpl as you suggested… but the error still persists. Also, my implementation is identical with the original one i found on github… so i’m 100% sure it’s not my implementation that causes the crash.
Please help !

Hi,
Let’s override the default Metadata implementation.
First of all, we should create a new class that implements Metadata interface -
com.company.overridingmetadatacomponent.core.sys.MyMetadataImpl:

public class MyMetadataImpl implements Metadata {
    private final Logger log = LoggerFactory.getLogger(MyMetadataImpl.class);
    ...
}

I’ve copied implementation from the MetadataImpl class and changed only one method for demonstration:

@Override
public <T> T create(Class<T> entityClass) {
    log.info(">>> Hello from custom Metadata impl!");

    return __create(entityClass);
}

The second (and the last) step is to register our implementation in the spring.xml file (it is placed in the core module):

<bean id="cuba_Metadata"
      class="com.company.overridingmetadatacomponent.core.sys.MyMetadataImpl"/>

And you can check that everything is OK when the app is starting:
public://attachments/cc3250e921b611d8cef3e1d1513f2bfa.png
Best regards,
Daniil.

cc3250e921b611d8cef3e1d1513f2bfa