1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
@Controller public class WelcomeController implements ApplicationContextAware, BeanNameAware {
private String myName; private ApplicationContext applicationContext;
@Autowired private WelcomeService welcomeService; public void sayHello(){ welcomeService.sayHello("hello controller"); System.out.println("myName="+myName); String applicationName = applicationContext.getApplicationName(); System.out.println("applicationName="+applicationName); }
@Override public void setBeanName(String name) { this.myName=name; }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext=applicationContext; } }
|