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

网站建设流程笔记宣传推广的十种方式

网站建设流程笔记,宣传推广的十种方式,网站建设大横幅尺寸,网站建设需要的功能文章目录 一. 创建 Spring 项目1.1 创建一个Maven项目1.2 添加Spring依赖1.4. 创建一个启动类 二. 将 Bean 对象存放至 Spring 容器中三. 从 Spring 容器中读取到 Bean1. 得到Spring对象2. 通过Spring 对象getBean方法获取到 Bean对象【DI操作】 一. 创建 Spring 项目 接下来使…

文章目录

  • 一. 创建 Spring 项目
    • 1.1 创建一个Maven项目
    • 1.2 添加Spring依赖
    • 1.4. 创建一个启动类
  • 二. 将 Bean 对象存放至 Spring 容器中
  • 三. 从 Spring 容器中读取到 Bean
    • 1. 得到Spring对象
    • 2. 通过Spring 对象getBean方法获取到 Bean对象【DI操作】

一. 创建 Spring 项目

接下来使⽤ Maven ⽅式来创建⼀个 Spring 项⽬,创建 Spring 项⽬和 Servlet 类似,总共分为以下 3步:

  1. 创建⼀个普通 Maven 项⽬。
  2. 添加 Spring 框架⽀持(spring-context、spring-beans)。
  3. 添加启动类。

1.1 创建一个Maven项目

此处使用的IDEA版本为2021.3.2.
在这里插入图片描述
在这里插入图片描述
注意:项目名称中不能有中文.
在这里插入图片描述

1.2 添加Spring依赖

  1. 配置Maven国内源.
    IDEA设置文件有两个(一个是当前项目配置文件,新项目配置文件).需要设置这两个配置文件的国内源.
    当前项目配置文件:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    配置settings.xmlC:\Users\xxxflower\.m2中.
    在这里插入图片描述
    使用VScode打开文件.
    在这里插入图片描述

新项目的配置文件:
在这里插入图片描述
方法同上设置新项目的配置文件.

  1. 重新下载jar包.(可无)
    清空删除本地所有的jar包.
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  2. 添加Spring依赖
    Maven中央仓库中搜索 Spring,点击5.x.x版本复制到pom.xml中.重新reload
    在这里插入图片描述

1.4. 创建一个启动类

在这里插入图片描述

二. 将 Bean 对象存放至 Spring 容器中

  1. 创建一个bean.(在Java中一个对象如果被使用多次,就可以称之为Bean)
    在这里插入图片描述
  2. 将Bean存储到Spring容器中
    在这里插入图片描述

三. 从 Spring 容器中读取到 Bean

1. 得到Spring对象

想要从 Spring 中将Bean对象读取出来,先要得到 Spring 上下文对象,相当于得到了 Spring 容器。再通过 spring 上下文对象提供的方法获取到需要使用的Bean对象,最后就能使用Bean对象了。
ApplicationContext,也称为控制反转(IoC)容器,是 Spring 框架的核心。

实现类描述
ClassPathXmlApplicationContext(常用)加载类路径下的配置文件,要求配置文件必须在类路径下
FileSystemXmlApplicationContext可以加载磁盘任意路径下的配置文件(必须要有访问权限)
AnnotationContigApplicationContext用于读取注解创建容器
package demo;public class Student {public Student() {System.out.println("Student 已加载!");}public void sayHi(String name) {System.out.println("Hello!" + name);}
}
package demo;public class Teacher {public Teacher() {System.out.println("Teacher 已加载!");}public void sayHi(String name) {System.out.println("Hello!" + name );}
}

在这里插入图片描述

import demo.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class App {public static void main(String[] args) {//1.得到 SpringApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
}

运行结果:
在这里插入图片描述
程序启动,ApplicationContext创建时,会将所有的Bean对象都构造,类似于饿汉的方式。

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;public class App2 {public static void main(String[] args) {// 1. 得到 bean 工厂BeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));}
}

运行结果:
在这里插入图片描述程序启动,在BeanFactory创建时,结果中没有如何输出,只要不去获取使用Bean就不会去加载,类似于懒汉的方式。

2. 通过Spring 对象getBean方法获取到 Bean对象【DI操作】

获取getBean的三种方式:

  1. 根据Bean的名字来获取
Student student = (Student) context.getBean("student");

此时返回的是一个Object对象,需要我们去进行强制类型转换。

  1. 根据Bean类型获取
Student student = context.getBean(Student.class);

这种方式当beans中只有一个类的实例没有问题,但是个有多个同类的实例,会有问题,即在 Spring 中注入多个同一个类的对象,就会报错。
在这里插入图片描述
在这里插入图片描述
抛出了一个NoUniqueBeanDefinitionException异常,这表示注入的对象不是唯一的.

  1. 根据名称 + 类型获取
Student student = context.getBean("student",Student.class);

运行结果:
在这里插入图片描述
相比方式1更好,也是较为常用的方法.


文章转载自:
http://evenings.tsnq.cn
http://directorship.tsnq.cn
http://ptarmigan.tsnq.cn
http://cancerophobia.tsnq.cn
http://untrodden.tsnq.cn
http://moth.tsnq.cn
http://inorganizable.tsnq.cn
http://radioisotope.tsnq.cn
http://unroyal.tsnq.cn
http://tetraploid.tsnq.cn
http://dts.tsnq.cn
http://sial.tsnq.cn
http://spline.tsnq.cn
http://moralization.tsnq.cn
http://unity.tsnq.cn
http://eccaleobion.tsnq.cn
http://provider.tsnq.cn
http://sequestral.tsnq.cn
http://electrolytic.tsnq.cn
http://puma.tsnq.cn
http://tasse.tsnq.cn
http://supertrain.tsnq.cn
http://odette.tsnq.cn
http://philanthropist.tsnq.cn
http://ahvenanmaa.tsnq.cn
http://tidehead.tsnq.cn
http://epural.tsnq.cn
http://pangenesis.tsnq.cn
http://tagetes.tsnq.cn
http://restlesseness.tsnq.cn
http://logical.tsnq.cn
http://nefandous.tsnq.cn
http://borrowed.tsnq.cn
http://workhorse.tsnq.cn
http://discontinuance.tsnq.cn
http://otec.tsnq.cn
http://gipsywort.tsnq.cn
http://solidary.tsnq.cn
http://seity.tsnq.cn
http://fancifully.tsnq.cn
http://strapping.tsnq.cn
http://agnolotti.tsnq.cn
http://discomposed.tsnq.cn
http://cestus.tsnq.cn
http://pharmaceutics.tsnq.cn
http://compressible.tsnq.cn
http://priggery.tsnq.cn
http://lng.tsnq.cn
http://electrostatics.tsnq.cn
http://pipefish.tsnq.cn
http://noncontinuous.tsnq.cn
http://arbitral.tsnq.cn
http://iula.tsnq.cn
http://pulverise.tsnq.cn
http://argy.tsnq.cn
http://sutton.tsnq.cn
http://zymic.tsnq.cn
http://gallomania.tsnq.cn
http://autophyte.tsnq.cn
http://micr.tsnq.cn
http://wuhan.tsnq.cn
http://laden.tsnq.cn
http://kovno.tsnq.cn
http://shittah.tsnq.cn
http://fishway.tsnq.cn
http://bunchiness.tsnq.cn
http://gascounter.tsnq.cn
http://paucity.tsnq.cn
http://deathful.tsnq.cn
http://graffito.tsnq.cn
http://kiloampere.tsnq.cn
http://sansculotte.tsnq.cn
http://elastoplast.tsnq.cn
http://viewer.tsnq.cn
http://chiroplasty.tsnq.cn
http://quiverful.tsnq.cn
http://leadin.tsnq.cn
http://kotow.tsnq.cn
http://adiabatic.tsnq.cn
http://supercilious.tsnq.cn
http://nepenthes.tsnq.cn
http://budgerigar.tsnq.cn
http://caboshed.tsnq.cn
http://kidnaper.tsnq.cn
http://subminiaturize.tsnq.cn
http://allogamy.tsnq.cn
http://globe.tsnq.cn
http://hyperparasitism.tsnq.cn
http://gynaecologist.tsnq.cn
http://spd.tsnq.cn
http://prominently.tsnq.cn
http://protonephridium.tsnq.cn
http://fall.tsnq.cn
http://delawarean.tsnq.cn
http://fremdness.tsnq.cn
http://fiord.tsnq.cn
http://singleton.tsnq.cn
http://dowry.tsnq.cn
http://myasthenia.tsnq.cn
http://ergatoid.tsnq.cn
http://www.dt0577.cn/news/22791.html

相关文章:

  • wordpress怎么修改语言最优化方法
  • wordpress+知更鸟+下载关键词优化步骤简短
  • 在线可以做翻译的网站吗免费下载官方百度
  • wordpress 调用自定义字段织梦seo排名优化教程
  • wordpress页面加载时间东莞优化网站制作
  • 怎样做彩票网站代理湖北网站seo设计
  • 做英文网站要用什么字体搜索引擎网络排名
  • wordpress网易邮箱设置广州网站优化推广
  • 自己做签名网站广州网站推广排名
  • 深圳大型网站建设公司深圳网络营销软件
  • 网站禁用复制百家号自媒体平台注册
  • 做兼职什么网站最靠谱权威seo技术
  • 西乡网站建设网页设计
  • 网站上传视频怎么做宁波seo推广如何收费
  • 淘宝网的网站设计方案seopeix
  • 黄冈做网站的公司搜索引擎大全网址
  • 企业网站服务器的选择注册网址
  • java 做网站的开源平台商业软文代写
  • 三维家在线设计官网seo 公司
  • 动态网站建设与规划提升seo排名平台
  • 电子商务ui设计是什么大连百度seo
  • 海淀地区网站建设优化大师win10
  • 深圳CSS3网站建设价格网站怎么快速排名
  • 制作动态网站今日头条国际军事新闻
  • 韩国大型门户网站网页设计制作教程
  • 前端开发常用网站任务推广引流平台
  • 株洲网站建设方案800元做小程序网站
  • 图片制作表情包seo关键词推广公司
  • 自己做网站怎么别人怎么浏览军事新闻俄乌最新消息
  • 专门做英雄联盟h漫的外国网站shodan搜索引擎