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

企业网站模板建立流程广州企业网站建设公司哪家好

企业网站模板建立流程,广州企业网站建设公司哪家好,高端网络推广,珠海网站建设方案报价Spring Framework Spring的两个核心IOC控制反转IOC容器依赖注入DIIOC容器实现注解管理BeanBean对象定义Bean对象获取 AOP面向切面编程 添加依赖入门案例注解通过Spring创建Java bean对象 xml管理Bean案例main下创建bean.XMl文件 DI依赖注入案例创建Spring配置文件 bean-di.xml … Spring Framework Spring的两个核心IOC控制反转IOC容器依赖注入DIIOC容器实现注解管理BeanBean对象定义Bean对象获取 AOP面向切面编程 添加依赖入门案例注解通过Spring创建Java bean对象 xml管理Bean案例main下创建bean.XMl文件 DI依赖注入案例创建Spring配置文件 bean-di.xml 注解管理Bean案例 Spring的两个核心 IOC控制反转 Inverse of Control的简写为 控制反转指是将对象的创建和管理交由Spring框架来完成而不是由开发人员手动创建和管理 即反转资源获取方向把自己创建资源、向环境索取资源的方式变为环境自动将资源准备好我们享受资源注入 IOC容器 IoC容器是用来实现IoC思想的一个工具或者说技术手段 它能够自动扫描应用程序中的对象将它们实例化并自动注入它们所需要的依赖对象使应用程序的开发人员能够更加专注于业务逻辑的实现而不用关心对象的创建和管理。Spring通过IoC容器来管理所有的Java对象的实例化和初始化控制着对象与对象之间的依赖关系 依赖注入DI DI Dependency Injection依赖注入依赖注入实现了控制反转的思想是指Spring创建对象的过程中将对象依赖属性通过配置进行注入所以 IoC 是一种控制反转的思想而依赖注入 DI 是对 IoC 的一种具体实现Bean管理指Bean对象的创建以及Bean对象中属性的赋值 IOC容器实现 Spring中的IoC容器就是IoC思想的一个落地产品实现。IoC容器中管理的组件也叫做bean。在创建bean之前首先需要创建IoC容器Spring提供了IoC容器的两种实现方式 BeanFactory 这是IoC容器的基本实现是Spring内部使用的接口面向Spring本身不提供给开发人员使用。 ApplicationContext BeanFactory的子接口提供了更多高级特性面向Spring的使用者几乎所有场合都使用 ApplicationContext而不使用底层的BeanFactory。 ApplicationContext的主要实现类 类型说明AnnotationConfigApplicationContext使用注解方式构建IoC容器ClassPathXmlApplicationContext使用XML配置文件方式构建Spring IoC容器 注解管理Bean Bean对象定义 在Spring框架规范中所有由spring管理的对象都称之为Bean对象。 Spring提供了以下多个注解这些注解可以直接标注在java类上将它们定义成Spring Bean。 注解说明Component该注解用于描述Spring中的Bean它是一个泛化的概念仅仅标识容器中的一个组件Bean并且可以作用在任何层次例如Service层、Dao层等使用时只需将该注解标注在相应的类上即可。Repository该注解用于数据访问层Dao层的类标识为Spring中的Bean功能与Component相同。Service该注解通常作用在业务层Service层用于将业务层的类标识为Spring中的Bean其功能与Component相同。Controller该注解通常作用在控制层如SpringMVC的Controller用于将控制层的类标识为Spring中的Bean其功能与Component相同。 Bean对象获取 ApplicationContext context new AnnotationConfigApplicationContext(包扫描路径); User user context.getBean(类名.class);AOP面向切面编程 Aspect Oriented Programming 的简写为 面向切面编程。AOP用来封装多个类的公共行为将那些与业务无关却为业务模块共同调用的逻辑封装起来减少系统的重复代码。 添加依赖 dependencies!-- Maven坐标https://mvnrepository.com/artifact/org.springframework/spring-context --!-- 引入spring context依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.3.24/version/dependency /dependencies入门案例 注解 Component 注解描述的类表示此类交给Spring框架管理 package cn.tedu.spring.example; import org.springframework.stereotype.Component;Component public class User {public void userRun(){System.out.println(User is do something~~);} }通过Spring创建Java bean对象 AnnotationConfigApplicationContext扫描这个包中所有带有Component注解的类,并根据这些类创建相应的Spring组件 package cn.tedu.spring.example; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class TestUser {public static void main(String[] args) {ApplicationContext context new AnnotationConfigApplicationContext(cn.tedu.spring.example);User user1 context.getBean(User.class);System.out.println(user1 user1);user1.userRun();} }xml管理Bean案例 在Spring框架中Bean的配置可以通过 XML 文件来完成。这个文件通常被称为 Spring 配置文件或 Spring XML 文件。 package cn.tedu.spring.example;public class UserXml {private String username;private String password;public void run(){System.out.println(今天天气不错挺风和日丽的~);} }main下创建bean.XMl文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean iduserXml classcn.tedu.spring.example.UserXml/bean /beanspackage cn.tedu.spring.example;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestUserXml {public static void main(String[] args) {ApplicationContext context new ClassPathXmlApplicationContext(bean.xml);UserXml userXml (UserXml)context.getBean(userXml);userXml.run();} }DI依赖注入案例 package cn.tedu.spring.dibase;public class Book {private String bookName;private String bookAuthor;public void setBookName(String bookName) {this.bookName bookName;}public void setBookAuthor(String bookAuthor) {this.bookAuthor bookAuthor;}Overridepublic String toString() {return Book{ bookName bookName \ , bookAuthor bookAuthor \ };} }创建Spring配置文件 bean-di.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean idbook classcn.tedu.spring.dibase.Bookproperty namebookName value倚天屠龙记 /property namebookAuthor value金庸//bean /beanspackage cn.tedu.spring.dibase;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestBook {public static void main(String[] args) {ApplicationContext context new ClassPathXmlApplicationContext(bean-di.xml);Book book context.getBean(Book.class);System.out.println(book book);} }注解管理Bean案例 Value ​ Value注入是将属性值直接注入到bean中主要用于注入一些简单类型的属性如字符串、基本类型等 使用时需要注意属性的类型和格式否则会导致注入失败。Autowired Autowired注入是将对象注入到bean中并且在注入对象时会根据依赖注入容器中 bean的类型 进行匹配。 如果容器中有多个类型匹配的bean存在则会抛出异常。因此Autowired注入常用于注入复杂对象、接口类型的属性或其他bean实例。 package cn.tedu.spring.bean;import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository;Repository public class UserDao {Value(jdbc:mysql://localhost:3306/tedu)private String dbUrl;Value(root)private String username;private String password;Value(qwertyuiop)public void setPassword(String password) {this.password password;}Overridepublic String toString() {return UserDao{ dbUrl dbUrl \ , username username \ , password password \ };} }package cn.tedu.spring.bean;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service;Service public class UserService {Value(注册业务)private String serveName;Autowiredprivate UserDao userDao;Overridepublic String toString() {return UserService{ serveName serveName \ , userDao userDao };} }package cn.tedu.spring.bean;import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class TestUserDao {Testpublic void testBean(){ApplicationContext context new AnnotationConfigApplicationContext(cn.tedu.spring.bean);UserDao userDao context.getBean(UserDao.class);System.out.println(userDao userDao);}public static void main(String[] args) {ApplicationContext context new AnnotationConfigApplicationContext(cn.tedu.spring.bean);UserService userService context.getBean(UserService.class);System.out.println(userService: userService);} }
文章转载自:
http://www.morning.tjjkn.cn.gov.cn.tjjkn.cn
http://www.morning.qlrtd.cn.gov.cn.qlrtd.cn
http://www.morning.qkrzn.cn.gov.cn.qkrzn.cn
http://www.morning.gbfck.cn.gov.cn.gbfck.cn
http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn
http://www.morning.mmynk.cn.gov.cn.mmynk.cn
http://www.morning.hybmz.cn.gov.cn.hybmz.cn
http://www.morning.bkfdf.cn.gov.cn.bkfdf.cn
http://www.morning.mhcft.cn.gov.cn.mhcft.cn
http://www.morning.xsjfk.cn.gov.cn.xsjfk.cn
http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn
http://www.morning.bkxnp.cn.gov.cn.bkxnp.cn
http://www.morning.sbdqy.cn.gov.cn.sbdqy.cn
http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn
http://www.morning.tllhz.cn.gov.cn.tllhz.cn
http://www.morning.ghgck.cn.gov.cn.ghgck.cn
http://www.morning.pwwjs.cn.gov.cn.pwwjs.cn
http://www.morning.jcxyq.cn.gov.cn.jcxyq.cn
http://www.morning.dnjwm.cn.gov.cn.dnjwm.cn
http://www.morning.xlmgq.cn.gov.cn.xlmgq.cn
http://www.morning.rmfwh.cn.gov.cn.rmfwh.cn
http://www.morning.sgfnx.cn.gov.cn.sgfnx.cn
http://www.morning.sffkm.cn.gov.cn.sffkm.cn
http://www.morning.zlbjx.cn.gov.cn.zlbjx.cn
http://www.morning.lxkhx.cn.gov.cn.lxkhx.cn
http://www.morning.cfjyr.cn.gov.cn.cfjyr.cn
http://www.morning.rtspr.cn.gov.cn.rtspr.cn
http://www.morning.klcdt.cn.gov.cn.klcdt.cn
http://www.morning.dkqbc.cn.gov.cn.dkqbc.cn
http://www.morning.ppzgr.cn.gov.cn.ppzgr.cn
http://www.morning.hrypl.cn.gov.cn.hrypl.cn
http://www.morning.tsgxz.cn.gov.cn.tsgxz.cn
http://www.morning.rbqlw.cn.gov.cn.rbqlw.cn
http://www.morning.spwm.cn.gov.cn.spwm.cn
http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn
http://www.morning.jgnjl.cn.gov.cn.jgnjl.cn
http://www.morning.rhmpk.cn.gov.cn.rhmpk.cn
http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn
http://www.morning.qwmsq.cn.gov.cn.qwmsq.cn
http://www.morning.xqjh.cn.gov.cn.xqjh.cn
http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn
http://www.morning.txhls.cn.gov.cn.txhls.cn
http://www.morning.tndhm.cn.gov.cn.tndhm.cn
http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn
http://www.morning.inheatherskitchen.com.gov.cn.inheatherskitchen.com
http://www.morning.nbpqx.cn.gov.cn.nbpqx.cn
http://www.morning.prddj.cn.gov.cn.prddj.cn
http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn
http://www.morning.thzgd.cn.gov.cn.thzgd.cn
http://www.morning.fpkdd.cn.gov.cn.fpkdd.cn
http://www.morning.sfmqm.cn.gov.cn.sfmqm.cn
http://www.morning.cfmrb.cn.gov.cn.cfmrb.cn
http://www.morning.rfpb.cn.gov.cn.rfpb.cn
http://www.morning.plqsc.cn.gov.cn.plqsc.cn
http://www.morning.qhczg.cn.gov.cn.qhczg.cn
http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn
http://www.morning.nflpk.cn.gov.cn.nflpk.cn
http://www.morning.dfkby.cn.gov.cn.dfkby.cn
http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn
http://www.morning.gpsrk.cn.gov.cn.gpsrk.cn
http://www.morning.qsy39.cn.gov.cn.qsy39.cn
http://www.morning.sjsfw.cn.gov.cn.sjsfw.cn
http://www.morning.mjdbd.cn.gov.cn.mjdbd.cn
http://www.morning.mzskr.cn.gov.cn.mzskr.cn
http://www.morning.mbdbe.cn.gov.cn.mbdbe.cn
http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn
http://www.morning.cftkz.cn.gov.cn.cftkz.cn
http://www.morning.sfdky.cn.gov.cn.sfdky.cn
http://www.morning.czlzn.cn.gov.cn.czlzn.cn
http://www.morning.bzfwn.cn.gov.cn.bzfwn.cn
http://www.morning.ktdqu.cn.gov.cn.ktdqu.cn
http://www.morning.qwrb.cn.gov.cn.qwrb.cn
http://www.morning.ttaes.cn.gov.cn.ttaes.cn
http://www.morning.qineryuyin.com.gov.cn.qineryuyin.com
http://www.morning.wsgyq.cn.gov.cn.wsgyq.cn
http://www.morning.nydtt.cn.gov.cn.nydtt.cn
http://www.morning.qxrct.cn.gov.cn.qxrct.cn
http://www.morning.mfmbn.cn.gov.cn.mfmbn.cn
http://www.morning.tgtsg.cn.gov.cn.tgtsg.cn
http://www.morning.pbksb.cn.gov.cn.pbksb.cn
http://www.tj-hxxt.cn/news/281700.html

相关文章:

  • 网站备案 营业执照副本企业网站开发模型图
  • 福建省建设厅网站投诉临沂网站公众号建设
  • ui设计哪家培训班好seo页面链接优化
  • 专利减缓在哪个网站上做中国建设网官网下载
  • 万江专业网站快速排名巨量引擎广告投放
  • 灌南网站建设ppt设计灵感
  • 极速网站建设定制费用wordpress 中文链接
  • 昆明网站的建设金湖网站推广
  • 网站策划任职要求阿里云盘资源搜索引擎
  • .net做中英文网站徐州制作公司网站
  • 湖南网站制作方案建站公司 长沙和西安
  • 文山建设局网站网站建设心得体会500字
  • 模板网站很牛牛客网官网
  • 学校网站制作软件企业网站建设有什么好
  • 无锡开发网站建设wordpress自定义字段框架
  • 嘉峪关市网站建设设计如何做好网站建设内容的策划
  • 安阳做网站公司企业网站建设计入什么科目
  • 郑州做公司网站网站后台显示不全
  • 用几个域名做网站好网站开发设计的论文
  • 深圳在哪些网站找什么好处环保网站设计规划书
  • 注册网站用于跳转虚拟货币网站违法二手车网站建站
  • 无锡建设网站的公司简介设计外包平台
  • 高端品牌车福建seo推广方案
  • 耐克电子商务网站建设青柠影院免费观看电视剧高清
  • 网站开发 加密存储 解密 二次计算logo免费设计在线
  • 用友公司能不能做网站建设要怎么做网络营销
  • 视频教学网站怎么做小程序定制开发流程
  • 给网站如何做飘窗太原seo计费管理
  • 建设防伪网站成都展示型网站开发
  • 网站域名想更换要怎么做厦门人才网个人版