当前位置: 首页 > news >正文

公司logo设计要求有哪些四平网站seo

公司logo设计要求有哪些,四平网站seo,网站菜单 网站导航,做网站商城文章目录 1. 什么是Bean,如何配置2. 如何配置bean2.1 使用注解Bean2.2 使用注解Import 1. 什么是Bean,如何配置 被spring容器所管理的对象被称为bean,管理方式可以有纯xml文件方式、注解方式进行管理(比如注解Component)。 在Spring Boot中&…

文章目录

    • 1. 什么是Bean,如何配置
    • 2. 如何配置bean
      • 2.1 使用注解@Bean
      • 2.2 使用注解@Import

1. 什么是Bean,如何配置

被spring容器所管理的对象被称为bean,管理方式可以有纯xml文件方式、注解方式进行管理(比如注解@Component)。
在Spring Boot中,在注解 @Component 的基础上,衍生出注解 @Service(专门用于处理业务类的注解)、@Repository(专门用于处理数据访问的注解)。

2. 如何配置bean

2.1 使用注解@Bean

在一个配置类上,定义一个方法,返回值为一个对象的实例化,在这个方法上添加注解@Bean,如下:

package com.lize.demo.dao;public class UserDao {public void printUserDao(){System.out.println("UserDao");}
}
package com.lize.demo.config;import com.lize.demo.dao.UserDao;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class SpringConnfig {@Beanpublic UserDao getUserDao(){return new UserDao();}
}

单元测试类如下:

package com.lize.demo;import com.lize.demo.dao.UserDao;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
class DemoApplicationTests {@Autowiredprivate UserDao ud;@Testvoid contextLoads() {ud.printUserDao();}
}

通过@Bean这种方式定义Bean,相比于直接在类上添加注解@component定义Bean。前者返回的是一个实例化对象,可以在这个过程中设置一些参数初始化Bean。

2.2 使用注解@Import

  • 需要写在类上;
  • 标记的类必须是一个bean,否则不会起作用;
@Component
@Import(UserDao.class)
public class SpringConnfig {}

上述只是基础写法。另外,可以实现ImportSelector这个接口,并重写其方法selectImports,这个方法返回的是一个字符串数组,字符串数组的值为类的完整路径,进行批量注入Bean,如下:

package com.lize.demo.config;import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;public class MyImportSelector implements ImportSelector {@Overridepublic String[] selectImports(AnnotationMetadata importingClassMetadata) {return new String[]{"com.lize.demo.dao.UserDao"};// 返回字符串数组}
}
@Component
@Import(MyImportSelector.class)
public class SpringConnfig {}

还有一种写法为,实现ImportBeanDefinitionRegistrar这个接口,并重写其方法registerBeanDefinitions,如下:

package com.lize.demo.config;import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;public class MyImportBeanDefinitionRegister implements ImportBeanDefinitionRegistrar {@Overridepublic void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {RootBeanDefinition definition = new RootBeanDefinition();definition.setBeanClassName("com.lize.demo.dao.UserDao");registry.registerBeanDefinition("UserDao",definition);}
}
package com.lize.demo.config;import com.lize.demo.dao.UserDao;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;@Component
@Import(MyImportBeanDefinitionRegister.class)
public class SpringConnfig {}
http://www.dinnco.com/news/370.html

相关文章:

  • 微博上如何做网站推广网站快速排名互点软件
  • 微网站微网站如何在百度投放广告
  • 常州网站制作机构整站优化提升排名
  • 网页站点的建立流程google play三件套
  • 营销型网站三要素高清免费观看电视网站
  • 做网站后的总结上海网站推广排名公司
  • 烟台58同城网站建设专业的网站建设公司
  • 建高铁站赚钱吗公司以优化为理由裁员合法吗
  • 安康市住房和城乡建设局网站浙江网站推广
  • 临沂建设局网站官网排行榜软件
  • 医院做网站备案都需要什么seo搜索引擎优化怎么优化
  • 个人备案的网站可以做商城吗合肥网络推广培训学校
  • 济南百度推广优化重庆seo外包平台
  • 娱乐网站建设免费seo优化工具
  • 剪辑课程哪里培训最好网站百度关键词seo排名优化
  • 网站访问量 显示代码宁波seo优化项目
  • 什么平台可以做网站帮别人推广app赚钱
  • 风水网站模板沈阳seo排名优化软件
  • 网站的搜索框如何做发布悬赏任务的推广平台
  • 网站怎么做sem正规教育培训机构
  • javaweb做网站的优点在线超级外链工具
  • 自己如何做电影网站上海免费关键词排名优化
  • 佛山哪有网站建设公司免费seo教程分享
  • 上海华谊集团建设有限公司网站北京疫情最新消息
  • 网站开发哪好宁波seo服务快速推广
  • 哪里有南宁网站建设网络推广费用一般多少
  • 建设局网站招聘app推广接单
  • 做网站的荣誉证书怎样建立个人网站
  • 网站规划图网络营销推广流程
  • 中山做网站建设联系电话自媒体账号申请