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

电子商务做网站骗钱怎么办seo推广方法集合

电子商务做网站骗钱怎么办,seo推广方法集合,wordpress单位内网做网站,兰溪网站一、配置优先级 SpringBoot 中支持三种格式的配置文件: 注意事项 虽然 springboot 支持多种格式配置文件,但是在项目开发时,推荐统一使用一种格式的配置 (yml 是主流)。 配置文件优先级排名(从高到低&…

一、配置优先级

SpringBoot 中支持三种格式的配置文件:
在这里插入图片描述

注意事项

  • 虽然 springboot 支持多种格式配置文件,但是在项目开发时,推荐统一使用一种格式的配置 (yml 是主流)。

配置文件优先级排名(从高到低):

  1. properties 配置文件
  2. yml 配置文件
  3. yaml 配置文件

SpringBoot 除了支持配置文件属性配置,还支持 Java 系统属性命令行参数 的方式进行属性配置。
在这里插入图片描述

优先级: 命令行参数 > 系统属性参数 > properties 参数 > yml 参数 > yaml 参数

项目已经打包上线了,这个时候我们又如何来设置Java系统属性和命令行参数呢?
在这里插入图片描述

注意事项

  • Springboot 项目进行打包时,需要引入插件 spring-boot-maven-plugin (基于官网骨架创建项目,会自动添加该插件)
    <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId>                </plugin></plugins></build>

二、Bean 管理

1 获取 Bean

默认情况下,Spring 项目启动时,会把 bean 都创建好放在 IOC 容器中,如果想要主动获取这些 bean,可以通过如下方式:

  • 根据 name 获取 bean:
    Object getBean(String name)
  • 根据类型获取 bean:
    <T> T getBean(Class<T> requiredType)
  • 根据 name获取 bean(带类型转换):
    <T> T getBean(String name, Class<T> requiredType)

上述所说的 【Spring 项目启动时,会把其中的 bean 都创建好】还会受到作用域及延迟初始化影响,这里主要针对于 默认的单例非延迟加载的 bean 而言。

@SpringBootTest
class SpringbootWebConfig2ApplicationTests {@Autowiredprivate ApplicationContext applicationContext; //IOC容器对象//获取bean对象@Testpublic void testGetBean(){//根据bean的名称获取DeptController bean1 = (DeptController) applicationContext.getBean("deptController");System.out.println(bean1);//根据bean的类型获取DeptController bean2 = applicationContext.getBean(DeptController.class);System.out.println(bean2);//根据bean的名称 及 类型获取DeptController bean3 = applicationContext.getBean("deptController", DeptController.class);System.out.println(bean3);}
}

2 Bean 作用域

Spring 支持五种作用域
在这里插入图片描述

可以通过 @Scope 注解来进行配置作用域:

//@Lazy
@Scope("prototype")
@RestController
@RequestMapping("/depts")
public class DeptController {
}

注意事项:

  • 默认 singleton 的 bean,在容器启动时被创建,可以使用 @Lazy 注解来延迟初始化(延迟到第一次使用时)。
  • prototype 的 bean,每一次使用该 bean 的时候都会创建一个新的实例。
  • 实际开发当中,绝大部分的 Bean 是单例的,也就是说绝大部分 Bean 不需要配置 scope 属性。
@SpringBootTest
class SpringbootWebConfig2ApplicationTests {@Autowiredprivate ApplicationContext applicationContext; //IOC容器对象//bean的作用域@Testpublic void testScope(){for (int i = 0; i < 10; i++) {DeptController deptController = applicationContext.getBean(DeptController.class);System.out.println(deptController);}}
}

3 第三方 Bean

如果要管理的 bean 对象来自于第三方(不是自定义的),是无法用 @Component 及衍生注解声明 bean 的,就需要用到 @Bean 注解。

解决方案1:在启动类上添加 @Bean 标识的方法(不建议,项目中要保证启动类的纯粹性)

@SpringBootApplication
public class SpringbootWebConfig2Application {public static void main(String[] args) {SpringApplication.run(SpringbootWebConfig2Application.class, args);}//声明第三方bean@Bean //将当前方法的返回值对象交给IOC容器管理, 成为IOC容器beanpublic SAXReader saxReader(){return new SAXReader();}
}
@SpringBootTest
class SpringbootWebConfig2ApplicationTests {@Autowiredprivate ApplicationContext applicationContext; //IOC容器对象@Autowiredprivate SAXReader saxReader;//第三方bean的管理@Testpublic void testThirdBean() throws Exception {//SAXReader saxReader = new SAXReader();Document document = saxReader.read(this.getClass().getClassLoader().getResource("1.xml"));Element rootElement = document.getRootElement();String name = rootElement.element("name").getText();String age = rootElement.element("age").getText();System.out.println(name + " : " + age);}
}

解决方案2:在配置类中定义 @Bean 标识的方法

  • 若要管理的第三方 bean 对象,建议对这些 bean 进行集中分类配置,可以通过 @Configuration 注解声明一个配置类。
@Configuration //配置类
public class CommonConfig {//声明第三方bean@Bean //将当前方法的返回值对象交给IOC容器管理, 成为IOC容器bean//通过@Bean注解的name/value属性指定bean名称, 如果未指定, 默认是方法名public SAXReader reader(DeptService deptService){System.out.println(deptService);return new SAXReader();}}

注意事项:

  • 通过 @Bean 注解的 name 或 value 属性可以声明 bean 的名称,如果不指定,默认 bean 的名称就是方法名。
  • 如果第三方 bean 需要依赖其它 bean 对象,直接在 bean 定义方法中设置形参即可,容器会根据类型自动装配。

@Component 及衍生注解 与 @Bean 注解使用场景?

  • 项目中自定义的,使用 @Component 及其衍生注解
  • 项目中引入第三方的,使用 @Bean 注解

三、SpringBoot 原理

在这里插入图片描述
通过 SpringBoot 来简化 Spring 框架的开发(是简化不是替代)。我们直接基于 SpringBoot 来构建 Java 项目,会让我们的项目开发更加简单,更加快捷。

在这里插入图片描述

  • 通过 SpringBoot 所提供的起步依赖,就可以大大的简化 pom 文件当中依赖的配置,从而解决了 Spring 框架当中依赖配置繁琐的问题。
  • 通过自动配置的功能就可以大大的简化框架在使用时 bean 的声明以及 bean 的配置。我们只需要引入程序开发时所需要的起步依赖,项目开发时所用到常见的配置都已经有了,我们直接使用就可以了。

1 起步依赖

为什么我们只需要引入一个 web 开发的起步依赖,web 开发所需要的所有的依赖都有了呢?

  • 因为 Maven 的依赖传递。
  • 在 SpringBoot 给我们提供的这些起步依赖当中,已提供了当前程序开发所需要的所有的常见依赖(官网地址:https://docs.spring.io/spring-boot/docs/2.7.7/referen
    ce/htmlsingle/#using.build-systems.starters )。
  • 比如:springboot-starter-web,这是 web 开发的起步依赖,在 web 开发的起步依赖当中,就集成了 web 开发中常见的依赖:json、web、webmvc、tomcat等。我们只需要引入这一个起步依赖,其他的依赖都会自动的通过 Maven 的依赖传递进来。

结论:起步依赖的原理就是 Maven 的依赖传递。

2 自动配置

2.1 概述

SpringBoot 的自动配置就是当 spring 容器启动后,一些配置类、bean 对象就自动存入到了 IOC 容器中,不需要我们手动去声明,从而简化了开发,省去了繁琐的配置操作。

2.2 方案一,@ComponentScan 组件扫描

@ComponentScan({"com.example","com.itheima"})
@SpringBootApplication
public class SpringbootWebConfig2Application {
}

缺点:

  1. 使用繁琐
  2. 性能低

2.3 方案二,@Import 导入

使用 @Import 导入的类会被 Spring 加载到 IOC 容器中,导入形式主要有以下几种:

  1. 导入 普通类
  2. 导入 配置类
  3. 导入 ImportSelector 接口实现类
  4. @EnableXxxx 注解,封装 @Import 注解(第三方依赖自己指定)
//@Import({TokenParser.class})//导入普通类,交给IOC容器管理
//@Import({HeaderConfig.class})//导入配置类,交给IOC容器管理
@Import({MyImportSelector.class})//导入ImportSelector接口实现类,交给IOC容器管理
@SpringBootApplication
public class SpringbootWebConfig2Application {public static void main(String[] args) {SpringApplication.run(SpringbootWebConfig2Application.class, args);}
}
public class MyImportSelector implements ImportSelector {public String[] selectImports(AnnotationMetadata importingClassMetadata) {return new String[]{"com.example.HeaderConfig"};}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Import(MyImportSelector.class)
public @interface EnableHeaderConfig {
}
@EnableHeaderConfig
@SpringBootApplication
public class SpringbootWebConfig2Application {public static void main(String[] args) {SpringApplication.run(SpringbootWebConfig2Application.class, args);}
}

2.4 原理分析

2.4.1 源码跟踪

在这里插入图片描述
@SpringBootApplication
该注解标识在 SpringBoot 工程引导类上,是 SpringBoot 中 最最最重要 的注解。该注解由三个部分组成:

  1. @SpringBootConfiguration:该注解与 @Configuration 注解作用相同,用来声明当前也是一个配置类。
  2. @ComponentScan:组件扫描,默认扫描当前引导类所在包及其子包。
  3. @EnableAutoConfiguration:SpringBoot 实现自动化配置的核心注解。

在这里插入图片描述

2.4.2 @Conditional
  • 作用:按照一定的条件进行判断,在满足给定条件后才会注册对应的 bean 对象到 Spring IOC 容器中。
  • 位置:方法、类
  • @Conditional 本身是一个父注解,派生出大量的子注解:
    1️⃣@ConditionalOnClass:判断环境中是否有对应字节码文件,才注册 bean 到 IOC 容器。
    2️⃣ @ConditionalOnMissingBean:判断环境中没有对应的 bean(类型 或 名称) ,才注册 bean 到 IOC 容器。
    3️⃣ @ConditionalOnProperty:判断配置文件中有对应属性和值,才注册 bean 到 IOC 容器。

在这里插入图片描述

@Configuration
public class HeaderConfig {@Bean@ConditionalOnClass(name = "io.jsonwebtoken.Jwts")// 环境中存在指定的这个类,才会将该bean加入IOC容器public HeaderParser headerParser1(){return new HeaderParser();}@Bean
//    @ConditionalOnMissingBean //当不存在当前类型(HeaderGenerator)的bean时,才声明该bean
//    @ConditionalOnMissingBean(name = "deptController2") //不存在指定名称的bean,才会将该bean加入IOC容器@ConditionalOnMissingBean(HeaderConfig.class)//不存在指定类型的bean,才会将bean加入IOC容器public HeaderGenerator headerGenerator(){return new HeaderGenerator();}@Bean@ConditionalOnProperty(name = "name" ,havingValue = "itheima")//配置文件中存在指定的属性与值,才会将该bean加入IOC容器public HeaderParser headerParser2(){return new HeaderParser();}}

2.5 案例

2.5.1 自定义 starter 分析

场景
在实际开发中,经常会定义一些公共组件,提供给各个项目团队使用。而在 SpringBoot 的项目中,一般会将这些公共组件封装为 SpringBoot 的 starter。

  • SpringBoot 官方 starter 命名: spring-boot-starter-xxxx
  • 第三组织提供的 starter 命名: xxxx-spring-boot-starter
    在这里插入图片描述
2.5.2 自定义 starter 实现

需求

  • 自定义 aliyun-oss-spring-boot-starter,完成阿里云 OSS 操作工具类 AliyunOSSUtils 的自动配置。
  • 目标:引入起步依赖引入之后,要想使用阿里云OSS,注入 AliyunOSSUtils直接使用即可。

步骤

  1. 创建 aliyun-oss-spring-boot-starter 模块
  2. 创建 aliyun-oss-spring-boot-autoconfigure 模块,在 starter 中引入该模块
  3. 在 aliyun-oss-spring-boot-autoconfigure 模块中的定义自动配置功能,并定义自动配置文件 META-INF/spring/xxxx.imports
    在这里插入图片描述
    (1)在 aliyun-oss-spring-boot-autoconfigure 模块中的定义自动配置功能,并定义自动配置文件 META-INF/spring/xxxx.imports

在 SpringBoot 项目中,并不会去扫描 com.aliyun.oss 这个包,所以注释 @Component 注解。

@Data
//@Component
@ConfigurationProperties(prefix = "aliyun.oss")
public class AliOSSProperties {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;
  • @Configuration 标识该类为配置类
  • @EnableConfigurationProperties 底层为 @Import
//@Component
@Configuration
@EnableConfigurationProperties(AliOSSProperties.class)
public class AliOSSAutoConfiguration {@Beanpublic AliOSSUtils aliOSSUtils(AliOSSProperties aliOSSProperties){AliOSSUtils aliOSSUtils = new AliOSSUtils();aliOSSUtils.setAliOSSProperties(aliOSSProperties);return aliOSSUtils;}
}

在 aliyun-oss-spring-boot-autoconfigure 模块中的 resources 下,新建自动配置文件:META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.impo
rts

com.aliyun.oss.AliOSSAutoConfiguration 

文章转载自:
http://dinncobeverley.knnc.cn
http://dinncosailcloth.knnc.cn
http://dinncoerythrocytosis.knnc.cn
http://dinncoknightlike.knnc.cn
http://dinncoringster.knnc.cn
http://dinncoannonaceous.knnc.cn
http://dinncoreshuffle.knnc.cn
http://dinncorabbit.knnc.cn
http://dinncoagreeably.knnc.cn
http://dinncofatuity.knnc.cn
http://dinncocrossjack.knnc.cn
http://dinncosublease.knnc.cn
http://dinncodesequestrate.knnc.cn
http://dinncopillular.knnc.cn
http://dinncomoped.knnc.cn
http://dinncocontinence.knnc.cn
http://dinncobacteriophobia.knnc.cn
http://dinnconondiscrimination.knnc.cn
http://dinncoexocytosis.knnc.cn
http://dinncoconchitis.knnc.cn
http://dinncohying.knnc.cn
http://dinncostratigrapher.knnc.cn
http://dinncotuc.knnc.cn
http://dinncominsk.knnc.cn
http://dinncoprincipally.knnc.cn
http://dinncofriary.knnc.cn
http://dinncocontiguity.knnc.cn
http://dinncoleisureful.knnc.cn
http://dinncolighthead.knnc.cn
http://dinncofalchion.knnc.cn
http://dinncopermillage.knnc.cn
http://dinncodressy.knnc.cn
http://dinncoforwards.knnc.cn
http://dinncobiosynthesize.knnc.cn
http://dinncora.knnc.cn
http://dinncophenocain.knnc.cn
http://dinncooverweigh.knnc.cn
http://dinncoflathead.knnc.cn
http://dinncostonker.knnc.cn
http://dinncountimeous.knnc.cn
http://dinncoworldwide.knnc.cn
http://dinncololiginid.knnc.cn
http://dinncounicostate.knnc.cn
http://dinncoguggenheim.knnc.cn
http://dinncolude.knnc.cn
http://dinncopsychosomimetic.knnc.cn
http://dinncofootbath.knnc.cn
http://dinncosalable.knnc.cn
http://dinncoreflower.knnc.cn
http://dinncoqanon.knnc.cn
http://dinncofustigate.knnc.cn
http://dinncohaemachrome.knnc.cn
http://dinncocryobiology.knnc.cn
http://dinncotramway.knnc.cn
http://dinncouptime.knnc.cn
http://dinncomicrodot.knnc.cn
http://dinncovermis.knnc.cn
http://dinncorounded.knnc.cn
http://dinncorevisal.knnc.cn
http://dinncomangosteen.knnc.cn
http://dinncobejeaned.knnc.cn
http://dinncocooperate.knnc.cn
http://dinncosendai.knnc.cn
http://dinncoalleyoop.knnc.cn
http://dinncocacoethes.knnc.cn
http://dinncojacobean.knnc.cn
http://dinncobarrel.knnc.cn
http://dinncoimmanuel.knnc.cn
http://dinncocomedown.knnc.cn
http://dinncolamprophyre.knnc.cn
http://dinncoresistible.knnc.cn
http://dinncostet.knnc.cn
http://dinncopathos.knnc.cn
http://dinncoindebtedness.knnc.cn
http://dinncopiggywiggy.knnc.cn
http://dinncohennery.knnc.cn
http://dinncostablish.knnc.cn
http://dinncogenet.knnc.cn
http://dinncoperioeci.knnc.cn
http://dinncohermit.knnc.cn
http://dinncovasodilator.knnc.cn
http://dinncocognizance.knnc.cn
http://dinncospeculator.knnc.cn
http://dinncopanatrophy.knnc.cn
http://dinncobiocytin.knnc.cn
http://dinncotuberose.knnc.cn
http://dinncoathenian.knnc.cn
http://dinncountender.knnc.cn
http://dinncointrinsical.knnc.cn
http://dinncotalkie.knnc.cn
http://dinncoskutari.knnc.cn
http://dinncomalar.knnc.cn
http://dinncoscalade.knnc.cn
http://dinncooversubtle.knnc.cn
http://dinncocasablanca.knnc.cn
http://dinncokimzeyite.knnc.cn
http://dinncotussor.knnc.cn
http://dinncozymoid.knnc.cn
http://dinncotrousers.knnc.cn
http://dinncohariana.knnc.cn
http://www.dinnco.com/news/106376.html

相关文章:

  • 哪建设网站五行seo博客
  • 网站嵌入英文地图百度网站推广申请
  • 郑州做网站 哪家好网站关键词上首页
  • 医院网站设计方案seo程序专员
  • 公司网站建设价格多少百度首页排名怎么做到
  • 情侣主题 wordpressseo网络营销推广
  • 惠州网站开发公司电话百度关键词推广公司哪家好
  • 网站建设总流程北京网站seo技术厂家
  • 微网站建设多少钱百度推广账户登录首页
  • 网站建设教程论坛百度收录的网页数量
  • 在线logo设计网站百度客服在线咨询
  • wordpress网站渗透测试百度手机下载安装
  • 网站建设得多少钱免费网络推广
  • 网站如何屏蔽ip百度文库首页官网
  • 淘宝客手机网站搭建上海优化公司有哪些
  • icp备案网站负责人推广app的营销方案
  • 红酒网站定位站长工具是做什么的
  • 新泰建设局网站项目推广计划书
  • 企信查怎么优化推广自己的网站
  • 化工厂建设网站seo网络培训班
  • 建立个人网站能干建立网站的流程
  • 前端和网站部署做网站的慧生活798app下载
  • 做那种类型的网站seo好seo关键词优化报价
  • 广州注册公司挂地址费用长沙 建站优化
  • 学生做的网站成品电商seo是什么
  • 做网站的主流软件推广普通话的意义是什么
  • 模板建站和仿站百度在西安的公司叫什么
  • 有了云服务器怎么做网站青岛网站建设方案服务
  • 腾讯云服务器上传网站聊城优化seo
  • 成都网站建设 四川冠辰上海百度移动关键词排名优化