spring半注解开发helloworld




    
   

@Component
public class Hello {

}
public class Application {
    public static void main(String[] args) {
       ApplicationContext context = new ClassPathXmlApplicationContext("my.xml");
        Hello hello = context.getBean("hello", Hello.class);
        System.out.println(hello);
    }
}

注解注入

@Controller(value = "goto")
public class Go {
    public void go(){
        System.out.println("go///");
    }
}

按类型和对象名称注入

@Component
public class Hello {
    @Autowired
    @Qualifier("goto")
    public Go go;
}

你可能感兴趣的:(spring半注解开发helloworld)