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

40个免费网站推广平台安徽建设工程信息网关闭 新网站

40个免费网站推广平台,安徽建设工程信息网关闭 新网站,广告横幅在线制作,互联网营销做什么Spring 就是⼀个包含了众多工具方法的 IoC 容器。既然是容器那么它就具备两个最基本的功能#xff1a; 将对象存储到容器#xff08;Spring#xff09;中从容器中将对象取出来 接下来使用 Maven 方式来创建一个 Spring 项目#xff0c;创建 Spring 项目和 Servlet 类似 将对象存储到容器Spring中从容器中将对象取出来 接下来使用 Maven 方式来创建一个 Spring 项目创建 Spring 项目和 Servlet 类似 在 Java 语言中对象也叫做 Bean所以后面咱们再遇到对象就以 Bean 著称。 1.创建 Spring 项目 接下来使用 Maven 方式来创建一个 Spring 项目创建 Spring 项目和 Servlet 类似总共分为以下3步 创建⼀个普通 Maven 项目添加 Spring 框架支持spring-context、spring-beans添加启动类 1.创建一个普通 Maven 项目 2.添加 Spring 依赖 在项目的 pom.xml 中添加 Spring 框架的支持 dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.2.3.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-beans/artifactIdversion5.2.3.RELEASE/version/dependency/dependencies?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdtest-2023-11-15/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.2.3.RELEASE/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-beans/artifactIdversion5.2.3.RELEASE/version/dependency/dependencies/project3.创建启动类 2.将 Bean 对象存储到 Spring (IoC容器) 1.创建一个 Bean 对象 2.将 Bean 存储到 Spring 中 在创建好的项目中添加 Spring 配置文件 spring-config.xml将此文件放到 resources 的根目录下 ?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.xsd/beans接下来再将 User 对象注册到 Spring 中就可以 bean iduser classcom.wjh.demo.UserService/bean3.从容器中获取 Bean 对象 1.得到 Spring 上下文对象 public class App {public static void main(String[] args) {//1.先得到 Spring 上下文对象ApplicationContext context new ClassPathXmlApplicationContext(spring-config.xml);} }2.获取到 Bean 对象 public class App {public static void main(String[] args) {//1.先得到 Spring 上下文对象ApplicationContext context new ClassPathXmlApplicationContext(spring-config.xml);//2.得到 Beancontext.getBean(user);} } 3.使用 Bean 对象 public class App {public static void main(String[] args) {//1.先得到 Spring 上下文对象ApplicationContext context new ClassPathXmlApplicationContext(spring-config.xml);//2.得到 Bean [依赖查找 - IoC 的一种实现]UserService userService (UserService) context.getBean(user);//3.使用 Bean 对象userService.sayHello();} }4.方法2 public class App2 {public static void main(String[] args) {//1.得到 Spring 上下文对象BeanFactory context new XmlBeanFactory(new ClassPathResource(spring-config.xml));//2.获取 BeanUserService userService (UserService) context.getBean(user);//3.使用 BeanuserService.sayHello();} }5.ApplicationContext 和 BeanFactory 的区别 保证线程安全问题: 1.使用锁 ( synchronized 锁升级的流程) 2.使用线程安全的容器 (底层锁实现) 3.ThreadLocal (本地线程变量) 相同点 : 都是容器管理对象,都可以获取到 Bean 对象 不同点: ApplicationContext 属于 BeanFactory 的子类,ApplicationContext 拥有更多的功能(对国际化支持、资源访问支持、以及事件传播等方面的支持…)加载 Bean 机制不同: BeanFactory 懒加载,按需加载(使用一个 Bean 加载一个 Bean) ApplicationContext 是⼀次性加载并初始化所有的 Bean 对象 我们加入一个 Student 类 public class App {public static void main(String[] args) {//1.先得到 Spring 上下文对象ApplicationContext context new ClassPathXmlApplicationContext(spring-config.xml);/* //2.得到 Bean [依赖查找 - IoC 的一种实现]UserService userService (UserService) context.getBean(user);//3.使用 Bean 对象userService.sayHello();*/} } public class App2 {public static void main(String[] args) {//1.得到 Spring 上下文对象BeanFactory context new XmlBeanFactory(new ClassPathResource(spring-config.xml));/* //2.获取 BeanUserService userService (UserService) context.getBean(user);//3.使用 BeanuserService.sayHello();*/} }6.getBean 方法的更多用法 根据名称获取 Bean 根据类型获取 Bean public class GetBeanExample {public static void main(String[] args) {//1.得到上下文对象ApplicationContext context new ClassPathXmlApplicationContext(spring-config.xml);//2.获取 BeanUserService userService context.getBean(UserService.class);//3.使用 BeanuserService.sayHello();} }区别就是:当有⼀个类型被重复注册到 spring-config.xml 中时只能使用根据名称获取了 根据 名称 类型 获取 public class GetBeanExample {public static void main(String[] args) {//1.得到上下文对象ApplicationContext context new ClassPathXmlApplicationContext(spring-config.xml);//2.获取 BeanUserService userService context.getBean(user, UserService.class);//3.使用 BeanuserService.sayHello();} }4.操作流程图
http://www.w-s-a.com/news/945119/

相关文章:

  • 松北区建设局网站网站建设分为几种
  • 网站建设的合同 体会智联招聘网站建设情况
  • 记的网站域名wordpress地方信息主题
  • 淄博好的建网站公司网站建设 海口
  • 有人做网站花了10几万2017做啥网站能致富
  • 做网站有什么软件cod建站平台
  • 合肥学校网站建设怎么做免费的产品图片网站
  • 营养早餐网站的设计与制作建设通网站怎么查项目经理在建
  • 浑南区建设局网站永州网站建设公司推荐
  • 做外贸都得有网站吗绵阳网站建设制作
  • 功能性的网站建设北京餐饮品牌设计公司
  • php做网站优势视频直播软件
  • 怎么安装php网站哪个网站是专门为建设方服务的
  • 重慶网站开发sina app engine wordpress
  • wampserver网站开发步骤中冠工程管理咨询有限公司
  • 自己做网站商城需要营业执照吗老外做牛排的视频网站
  • 网站推广效果的评估指标主要包括公司广告推广
  • 昆明网站建设那家好哪个网站学做凉皮
  • hype做网站动效哪里有给网站做
  • 打扑克网站推广软件设计类专业哪个最好
  • 网站设计首页网站建设意向书
  • 做网站要学那些angularjs后台管理系统网站
  • 广州白云手机网站建设学做点心上哪个网站
  • 哈尔滨网站建设步骤百度青岛代理公司
  • 怎么利用代码做网站军队 网站备案
  • 百度手机版网址免费广州seo
  • 军博做网站公司wordpress评论插件
  • 如何申请一个网站 做视频网站报错解析
  • 徐州高端网站建设无锡找做网站
  • 网站如何不需要备案百度的宣传视频广告