zoukankan      html  css  js  c++  java
  • spring新注解

    我们需要注意的是注解和注解修饰的类,方法,属性、是连在一起的,当我们引用使用注解修饰的类,我们也使用了注解

    @componentscan(value = {"包一",“包二”……})  这个表明需要扫描的包

    @Configuration(value = “S”)如下所示,表明默认值为当前类,表明讲当前类作为一个配置类

    public @interface Configuration {
    
        /**
         * Explicitly specify the name of the Spring bean definition associated with the
         * {@code @Configuration} class. If left unspecified (the common case), a bean
         * name will be automatically generated.
         * <p>The custom name applies only if the {@code @Configuration} class is picked
         * up via component scanning or supplied directly to an
         * {@link AnnotationConfigApplicationContext}. If the {@code @Configuration} class
         * is registered as a traditional XML bean definition, the name/id of the bean
         * element will take precedence.
         * @return the explicit component name, if any (or empty String otherwise)
         * @see AnnotationBeanNameGenerator
         */
        @AliasFor(annotation = Component.class)
        String value() default "";

    @Bean 修饰方法  将当前方法交给spring容器保管

     @Bean(value = "runner")
        public QueryRunner CreateQueryRunner(DataSource dataSource){//大红线表明容器中没有datasource这个对象
            return new QueryRunner(dataSource);
        }
    
        @Bean(value = "dataSource")//在容器中生成了datasource对象
        public DataSource CreateDataSoerce(){
            ComboPooledDataSource dataSource = new ComboPooledDataSource();
            try {
                dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
                dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/mydatabase");
                dataSource.setUser("root");
                dataSource.setPassword("123456");
                return dataSource;
    
            } catch (PropertyVetoException e) {
                throw new RuntimeException(e);
            }

    @PropertySource(classpath:"文件路徑")

  • 相关阅读:
    买车注意事项
    关节炎的成因
    改变seekbar的游标图片大小
    十大安卓应用商店推广渠道排行榜
    无线 WIFI 的13个信道频率范围
    了解RFC协议号
    图形图像专业术语
    Phpcms之L()函数
    PHPCMS V9 加密规则
    Sublime 快捷键
  • 原文地址:https://www.cnblogs.com/guosai1500581464/p/13360777.html
Copyright © 2011-2022 走看看