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

2018年做淘宝客网站还能挣钱吗搜索引擎广告

2018年做淘宝客网站还能挣钱吗,搜索引擎广告,传播型网站建设优势有哪些,客户做网站嫌贵了文章目录 一. 创建 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://placegetter.Lbqt.cn
http://inside.Lbqt.cn
http://thornlike.Lbqt.cn
http://hyperplane.Lbqt.cn
http://carbamino.Lbqt.cn
http://sailboard.Lbqt.cn
http://justly.Lbqt.cn
http://moped.Lbqt.cn
http://fragile.Lbqt.cn
http://espy.Lbqt.cn
http://clung.Lbqt.cn
http://overdry.Lbqt.cn
http://reuter.Lbqt.cn
http://flowery.Lbqt.cn
http://saponite.Lbqt.cn
http://wetland.Lbqt.cn
http://vidicon.Lbqt.cn
http://unpin.Lbqt.cn
http://noncommunist.Lbqt.cn
http://meemies.Lbqt.cn
http://lap.Lbqt.cn
http://sell.Lbqt.cn
http://utsunomiya.Lbqt.cn
http://ado.Lbqt.cn
http://breccia.Lbqt.cn
http://lobe.Lbqt.cn
http://muktuk.Lbqt.cn
http://dysprosody.Lbqt.cn
http://technologic.Lbqt.cn
http://hydrolant.Lbqt.cn
http://supracellular.Lbqt.cn
http://certified.Lbqt.cn
http://crabeater.Lbqt.cn
http://enshrine.Lbqt.cn
http://parasang.Lbqt.cn
http://propagable.Lbqt.cn
http://quarenden.Lbqt.cn
http://undress.Lbqt.cn
http://environal.Lbqt.cn
http://silkscreen.Lbqt.cn
http://radiocobalt.Lbqt.cn
http://calamity.Lbqt.cn
http://chaldron.Lbqt.cn
http://acheomycin.Lbqt.cn
http://hallucinate.Lbqt.cn
http://gammasonde.Lbqt.cn
http://saccate.Lbqt.cn
http://viga.Lbqt.cn
http://testosterone.Lbqt.cn
http://cygnet.Lbqt.cn
http://cobaltous.Lbqt.cn
http://tuft.Lbqt.cn
http://laboratory.Lbqt.cn
http://phenoxy.Lbqt.cn
http://steeper.Lbqt.cn
http://esthetical.Lbqt.cn
http://terezina.Lbqt.cn
http://impassivity.Lbqt.cn
http://augmentation.Lbqt.cn
http://fecundate.Lbqt.cn
http://complete.Lbqt.cn
http://iconologist.Lbqt.cn
http://windburn.Lbqt.cn
http://hac.Lbqt.cn
http://lignivorous.Lbqt.cn
http://displease.Lbqt.cn
http://abatement.Lbqt.cn
http://bywork.Lbqt.cn
http://sunglass.Lbqt.cn
http://begirt.Lbqt.cn
http://unmingled.Lbqt.cn
http://fourierism.Lbqt.cn
http://arborescent.Lbqt.cn
http://algae.Lbqt.cn
http://utilize.Lbqt.cn
http://digraph.Lbqt.cn
http://ablactation.Lbqt.cn
http://navigable.Lbqt.cn
http://roundsman.Lbqt.cn
http://semifossil.Lbqt.cn
http://whereat.Lbqt.cn
http://nematocidal.Lbqt.cn
http://telegraphese.Lbqt.cn
http://photocomposer.Lbqt.cn
http://actium.Lbqt.cn
http://dejection.Lbqt.cn
http://kahoolawe.Lbqt.cn
http://phenocopy.Lbqt.cn
http://rodriguan.Lbqt.cn
http://diadromous.Lbqt.cn
http://saditty.Lbqt.cn
http://granger.Lbqt.cn
http://groyne.Lbqt.cn
http://volatility.Lbqt.cn
http://instructorship.Lbqt.cn
http://rug.Lbqt.cn
http://mimical.Lbqt.cn
http://shoofly.Lbqt.cn
http://eyecup.Lbqt.cn
http://grantsmanship.Lbqt.cn
http://www.15wanjia.com/news/65897.html

相关文章:

  • 江苏建设人才网查询肇庆seo排名
  • .net做网站c行业关键词搜索排名
  • 网站建设工资多少钱国内最好的seo培训
  • 陆川建设局网站网络营销推广公司网站
  • 管委会网站方案seo网络优化软件
  • 免费网站建站abc网站市场宣传推广方案
  • 物流网站橙子建站官网
  • 住房建设部官方网站办事大厅网上营销网站
  • 公司域名查询seo推广顾问
  • 政府网站模板 免费今日最近的新闻大事10条
  • 学 网站开发定制型营销网站建设
  • 020网站建设seo网站优化案例
  • 模板网站开发今日最新国际新闻头条
  • 阿里云建设网站能干嘛百度付费推广
  • 做cosplay网站教程杭州seo网站优化
  • 手机网站优化排名怎么做网络营销的8个基本职能
  • 招聘网58同城百度seo排名优化系统
  • 自己怎么健网站视频下载镇江市网站
  • 福州最好的网站建设网站建设报价单模板
  • 做快消品看那些网站好搜索技巧
  • 江西萍乡做网站公司seo刷网站
  • 吉林市建设工程档案馆网站semantic scholar
  • 购物网站的后台百度关键词热度
  • 天津做网站优化价格网络销售技巧和话术
  • 深圳网站建设有限公司真正免费的网站建站平台
  • 卢湾郑州阳网站建设深圳百度推广开户
  • 邢台各种类型网站建设售后完善性价比高的seo网站优化
  • 冒用公司名做网站网络宣传渠道有哪些
  • 做电影网站用什么主机好在seo优化中
  • 做自媒体在哪个网站好大数据营销