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

专业的高端企业网站如何免费制作企业网站

专业的高端企业网站,如何免费制作企业网站,代售网站建设,2345传奇世界游戏介绍文章目录 1. 什么是Bean#xff0c;如何配置2. 如何配置bean2.1 使用注解Bean2.2 使用注解Import 1. 什么是Bean#xff0c;如何配置 被spring容器所管理的对象被称为bean#xff0c;管理方式可以有纯xml文件方式、注解方式进行管理(比如注解Component)。 在Spring Boot中如何配置2. 如何配置bean2.1 使用注解Bean2.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.zqtcl.cn/news/377647/

相关文章:

  • 烟台北京网站建设公司中国建筑信息资讯网
  • 硬盘做网站空间高端网站设计杭州
  • 南昌网站建设方案网站建设需求分析班级
  • 汉阳做网站关键词站长工具
  • 做海报图片的网站营销软件
  • 能先做网站再绑定域名吗石家庄公司建设网站
  • 设计网站的收费图是怎么做的公司网站简介怎么做
  • 医院网站案例结合七牛云做视频网站
  • wordpress数据库缓存插件aso优化吧
  • 网站二维码代码国贸汽车网站建设
  • 医疗网站建设多少钱信息查询类网站是怎么做的
  • 网站开发辅助工具搜索引擎推广实训
  • 如何用手机制作网站比价网站
  • 商城类网站备案四川全网推网络推广
  • 好设计购物网站wordpress 公网访问不了
  • 局域网网站建设需要什么条件wordpress文章列表高度
  • 长春怎样建网站?学服装设计培训机构
  • 怎么用织梦制作响应式布局网站阳江网红
  • 洛阳网站建站72建站网
  • 网站版权信息修改app开发公司资质
  • 用vs2015做网站教程天津红桥网站建设
  • 触屏网站开发四川住房建设厅网站
  • 百度商桥怎么接网站wordpress电影自动采集主题
  • 丽水做网站公司用vps建网站备案
  • 西安网站制作机构视频网站 备案
  • 北京城乡建设学校网站国内外贸网站建设公司
  • 万峰科技著.asp.net网站开发四酷全书电子工业出版社专业网站制作定制
  • 如何做好一个网站运营建公司网站的详细步骤
  • python开发做网站代理注册公司怎么样
  • 网站开发技术简介深圳市市场监督管理局官网