We want to have two interface implementations for production and development mode:
Consider the interface:
public interface AccountList { public List<Account> getAllAccounts(String userID) ; }
With two implementations:
Base implementation
@Service public AccountListImp1 interface AccountList { ... }
and some development implementation
@Service @Profile("Dev") public AccountListImp2 interface AccountList { ... }
When I try to use a bean:
public class TransferToAccount{ @Autowired private AccountServices accountServices; }
I get this error:
No qualifying bean of type [AccountList] is defined: expected single matching bean but found 2: coreSabaAccountList,dummyAccountList
During development, we set spring.profiles.active to dev , as shown below:
<context-param> <param-name>spring.profiles.active</param-name> <param-value>Dev</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
I suggested that setting the profile name will make spring categorize beans with different profiles and use them in the database by profile name.
Could you let me know how I can solve this? I can use @Primary or modify applicationContext.xml, but I think that @profile should solve my problem.
source share