Brief Description:
For Bean IDs, it is possible to create instances based on configuration dynamics when injected
Code:
Erepositoryconfigure.java
Package com.cpa.components.system.e.repository;
Import Org.apache.commons.lang3.Validate;
Import Org.springframework.beans.factory.annotation.Autowire;
Import Org.springframework.beans.factory.annotation.Value;
Import Org.springframework.context.annotation.Bean;
Import org.springframework.context.annotation.Configuration;
Import Com.cpa.components.system.e.repository.impl.edbrespository;
Import Com.cpa.components.system.e.repository.impl.eremoterepository; @Configuration public class Erepositoryconfigure {@Value ("${cpa.server.e.repository.group.type}") Private String type
;
Private Erepository repository; @Bean (Autowire = autowire.by_type, name = "Components.system.ERepository") public Erepository instance () {if (reposit
Ory = null) {return repository;
} switch (type) {case "Remote_system": Repository = new Eremoterepository ();
Break
Case "local_db": Repository = new Edbrespository ();
Break
Default:break; } validate.notnull (ReposiTory, "Invalid E repository type:[%s]", type);
return repository; }
}