美文网首页
spring半注解开发helloworld

spring半注解开发helloworld

作者: simplerandom | 来源:发表于2020-07-23 15:48 被阅读0次
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--读取配置文件扫描的路径-->
   <context:component-scan base-package="org.spring"/>
</beans>
@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

      本文链接:https://www.haomeiwen.com/subject/tbjhlktx.html