BeanNameAware test the result

This commit is contained in:
mherbaghinyan 2018-04-28 12:02:06 +04:00
parent 4b91a76d8f
commit 5dc1b18c29
4 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,7 @@
package com.baeldung.aware; package com.baeldung.aware;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/** /**
* Created by Gebruiker on 4/24/2018. * Created by Gebruiker on 4/24/2018.
*/ */
@ -7,5 +9,9 @@ public class AwareExample {
public static void main(String[] args) { public static void main(String[] args) {
AnnotationConfigApplicationContext context
= new AnnotationConfigApplicationContext(Config.class);
MyBeanName myBeanName = context.getBean(MyBeanName.class);
} }
} }

View File

@ -1,7 +1,13 @@
package com.baeldung.aware; package com.baeldung.aware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class Config { public class Config {
@Bean(name = "myCustomBeanName")
public MyBeanName getMyBeanName() {
return new MyBeanName();
}
} }

View File

@ -17,4 +17,6 @@ public class MyBeanFactory implements BeanFactoryAware {
this.beanFactory = beanFactory; this.beanFactory = beanFactory;
System.out.println(beanFactory); System.out.println(beanFactory);
} }
} }

View File

@ -2,9 +2,6 @@ package com.baeldung.aware;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
/**
* Created by Gebruiker on 4/25/2018.
*/
public class MyBeanName implements BeanNameAware { public class MyBeanName implements BeanNameAware {
@Override @Override