Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##### Код
- package tmpjavaproj;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.boot.SpringApplication;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- @Configuration
- public class Test {
- @Bean(name = { "aBean", "myBean" })
- public Object myBean() {
- return "Hi there";
- }
- @Bean(name = { "aBean", "yourBean" })
- public Object yourBean() {
- return "Bye here";
- }
- @Bean
- public Object check(@Autowired @Qualifier("myBean") Object myBean, @Autowired @Qualifier("yourBean") Object yourBean) {
- System.out.println(myBean + " // " + yourBean);
- return null;
- }
- public static void main(String[] args) {
- SpringApplication.run(Test.class);
- }
- }
- ##### Вивід
- Bye here // Bye here
- ##### Код №2
- package tmpjavaproj;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.boot.SpringApplication;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- @Configuration
- public class Test {
- @Bean(name = { "myBean", "aBean" })
- public Object myBean() {
- return "Hi there";
- }
- @Bean(name = { "yourBean", "aBean" })
- public Object yourBean() {
- return "Bye here";
- }
- @Bean
- public Object check(@Autowired @Qualifier("myBean") Object myBean, @Autowired @Qualifier("yourBean") Object yourBean) {
- System.out.println(myBean + " // " + yourBean);
- return null;
- }
- public static void main(String[] args) {
- SpringApplication.run(Test.class);
- }
- }
- ##### Вивід №2
- Hi there // Bye here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement