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

做网站怎么推广北京网站优化站优化

做网站怎么推广,北京网站优化站优化,用asp.net做的网站实例,学销售从哪里开始目录 1 Profiles 1.1 "组件"环境隔离 1.1.1 标识环境 1.1.2 激活环境 1.2 "配置"环境隔离 1.2.1 添加"副配置文件" 1.2.2 激活环境 2 外部化配置 2.1 配置优先级 2.2 快速部署 3 自定义starter 3.1 基本抽取 3.1.1 导yaml提示包 3…

目录

1 Profiles

1.1 "组件"环境隔离

1.1.1 标识环境

1.1.2 激活环境

1.2 "配置"环境隔离

1.2.1 添加"副配置文件"

1.2.2 激活环境

2 外部化配置

2.1 配置优先级

2.2 快速部署

3 自定义starter

3.1 基本抽取

3.1.1 导yaml提示包

3.1.2 【公共模块】抽取

3.1.3 【普通模块】引用

3.2 @EnableXxx注解抽取

3.3 自动配置抽取

3.3.1 SPI机制

3.3.2 全自动配置


1 Profiles

用于"环境隔离",能够快速切换开发环境(dev),测试环境(test),生产环境(prod)等

1.1 "组件"环境隔离

针对不同的环境,往SpringIOC容器中注册不同的组件

1.1.1 标识环境

        @Profile({"dev","test"})注解可以配合@Component等注解使用,也可以配合@Bean注解使用,标记当前组件在指定环境下生效

        没有标@Profile的类,在任何环境下都生效

        @Profile对于@EnableConfigurationProperties({Dog.class,Cat.class})中的Dog类、Cat类不生效(即Dog类用了@Profile也会被注册进SpirngIOC)

1.1.2 激活环境

        在properties.yaml文件中激活对应的环境,如果没有配置对应的"激活环境",则SpringBoot默认激活default环境; 如果配置了"激活环境",则default环境失效

spring:profiles:active: dev,test

1.2 "配置"环境隔离

针对不同的环境,选择生效的"副配置文件"(主配置文件application.yaml永远生效)

1.2.1 添加"副配置文件"

        例如:application-dev.yamlapplication-test.yamlapplication-prod.yaml

1.2.2 激活环境

        激活方式与1.1.2相同,且只能写在主配置文件中:

                例如:spring.profiles.active=dev,则application-dev.yaml生效

        如果"副配置文件"和"主配置文件"配置冲突,以"副配置文件"为准

2 外部化配置

2.1 配置优先级

        命令行 > 包内外  (例: java -jar demo.jar --server.port=9999)

        jar包外配置优先级 > jar包内配置优先级

        副配置优先级 > 主配置优先级

包内:(1)application.yaml       #server.port=8000(2)application-dev.yaml   #server.port=8001
包外:(3)application.yaml       #server.port=9000(4)application-dev.yaml   #server.port=9001//有(1),以(1)为准
//有(1)(2),以(2)为准
//有(1)(2)(3),以(2)为准
//有(1)(2)(3)(4),以(4)为准//执行的是命令行,以命令行为准

2.2 快速部署

        根据"配置优先级"的规则,当需要修改某一项配置,无需再重新打jar包部署,而只需要新建一个与jar包文件同级别的"外部配置文件",然后用java -jar命令再次执行jar包即可

3 自定义starter

        当我们在编写多个模块时,往往有许多重复代码,可以考虑将这些重复代码抽取出来作为一个starter,然后让模块去引用此starter即可

3.1 基本抽取

3.1.1 导yaml提示包

        在yaml中配置SpringBoot官方给的配置,当输入相关值的时候,会有提示

        而一些自定义的配置(例如:属性绑定时),则在yaml文件中不会有提示,而且被属性绑定的类还会被IDEA标红提示

        只需要引入spring提供的starter即可解决

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>

3.1.2 【公共模块】抽取

        (1) 创建公共模块,可以起名为xxx-xxx-spring-boot-starter

        (2) 导入此模块需要的依赖(jar包和starter),以及其它模块们都需要的公共依赖(这样其它模块就无须引入公共依赖了)

        (3) 抽取公共代码(例如:问候接口/hello/welcome)

        (4) 因为SpringBoot默认只会扫描自己主程序的包,外部引入的依赖包不会被扫描到,所以:

                在【公共模块】的Spring配置类中,用@import或@Bean引入需要注册的组件(如Controller,Service,pojo等)

                在【普通模块】引入【公共模块】后,在Spring配置类中用@Import或@Bean引入【公共模块】的Spring配置类

<!--新建一个【公共模块】,导入此模块需要的包,导入【普通模块】们都需要的公共依赖-->
<groupId>starter.xyz.aboluo</groupId>
<artifactId>aboluo-hello-spring-boot-starter</artifactId>
<version>1.0</version>// 【公共模块】抽取公共代码(以"问候接口/hello/welcome"为例)
@RestController
@RequestMapping("/hello")
public class HelloController {@Autowiredprivate HelloServiceImpl helloService;  //注意:这里@Autowired的是ServiceImpl类,并不是Service接口(因为在【普通模块】中加载不到)@PostMapping("/welcome")public String hello() {return helloService.hello();}
}//@Service  因为在Spring配置类中被用@Import引入了,此注解可以不写
public class HelloServiceImpl {@Autowiredprivate HelloProperties helloProperties;public String hello() {return helloProperties.getWelcomeMessage() + "本服务是由【" + helloProperties.getCompanyName() + "】公司提供技术支持";}
}//【自动配置类】
//@Component  因为在Spring配置类中被用@EnableConfigurationProperties引入了,此注解可以不写
@ConfigurationProperties(prefix = "hello")
public class HelloProperties {private String welcomeMessage;private String companyName;
}@SpringBootConfiguration
@ComponentScan("starter.xyz.aboluo")
//因为这些类在【普通模块】中不会被扫描到,所以全部引入到Spring配置类中
@Import({HelloController.class, HelloServiceImpl.class})
@EnableConfigurationProperties({Hello.class})
public class AboluoHelloAutoConfiguration {
}

3.1.3 【普通模块】引用

<!--【普通模块】引入"自定义starter"-->
<dependency><groupId>starter.xyz.aboluo</groupId><artifactId>aboluo-hello-spring-boot-starter</artifactId><version>1.0</version>
</dependency>//【普通模块】的Spring配置类中用@Import引入【公共模块】的Spring配置类
@SpringBootConfiguration
@MapperScan("xyz.aboluo.dao")
@Import(AboluoHelloAutoConfiguration.class)
public class SpringConfig {
}// 在yaml中对Hello类进行"属性绑定"
hello:welcome-message: 欢迎您的使用!company-name: 字节跳动//此时依赖【公共模块】的【普通模块】启动后,就可以访问到"问候接口/hello/welcome"

3.2 @EnableXxx注解抽取

        使用3.1的抽取方式的弊端:【普通模块】引入【公共模块】后,需要在Spring配置类上用@Import引入【公共模块】的Spring配置类

        利用Enable机制,可以在【公共模块】中自定义一个@EnableXxx注解,【普通模块】在Spring配置类使用【公共模块】的自定义注解即可,无需再使用@Import了

//【公共模块】自定义注解
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Documented
@Import({HelloController.class, HelloServiceImpl.class, Hello.class})
public @interface EnableHello {
}//【普通模块】的Spring配置类上使用"自定义注解"
@SpringBootConfiguration
@MapperScan("xyz.aboluo.dao")
@EnableHello
public class SpringConfig {
}

3.3 自动配置抽取

3.3.1 SPI机制

        (Java的SPI默认访问META-INF/services/目录下的文件)

        (SpringBoot的SPI默认访问META-INF/spring/目录下的文件)

        项目引入官方starter依赖时,这个starter会继续依赖spring-boot-starter,其中一个核心依赖是spring-boot-autoconfigure,此时SpirngBoot会触发一个行为,自动去找org.springframework.boot:spring-boot-autoconfigureMETA-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件

        此文件中所有的类(自动配置类一般写为XxxAutoConfiguration)会在项目启动时自动加载(被注册进SpringIOC),主要作用就是向SpringIOC容器中添加一些组件(用@Import或@Bean的方式)

        并且会用@EnableConfigurationProperties指定对应的配置属性类,开启属性绑定

3.3.2 全自动配置

        使用3.2的抽取方式,还需要在【普通模块】的Spring配置类写"自定义注解",有没有可能连自定义注解也不用写,直接引入【公共模块】就可以用呢?

        利用SPI机制,在【公共模块】"类资源文件夹"resource下放META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件,并写入Spring配置类(主要是要其中的@Import)的全限定类名

//新建resource/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件
starter.xyz.aboluo.boot.AboluoHelloAutoConfiguration@SpringBootConfiguration
@ComponentScan("starter.xyz.aboluo")
@Import({HelloController.class, HelloServiceImpl.class})
@EnableConfigurationProperties({HelloProperties.class})
public class AboluoHelloAutoConfiguration {
}

文章转载自:
http://wanjiastopper.ptzf.cn
http://wanjiaevoke.ptzf.cn
http://wanjiamutualism.ptzf.cn
http://wanjiacaroline.ptzf.cn
http://wanjiadocking.ptzf.cn
http://wanjiasmattering.ptzf.cn
http://wanjiaejectable.ptzf.cn
http://wanjiaimpairment.ptzf.cn
http://wanjiacouture.ptzf.cn
http://wanjiazn.ptzf.cn
http://wanjiaathenian.ptzf.cn
http://wanjiainterpellation.ptzf.cn
http://wanjiapenultimate.ptzf.cn
http://wanjiadocile.ptzf.cn
http://wanjiavaluative.ptzf.cn
http://wanjiaunmortared.ptzf.cn
http://wanjiasureness.ptzf.cn
http://wanjiaforearm.ptzf.cn
http://wanjiacheater.ptzf.cn
http://wanjiawidget.ptzf.cn
http://wanjiagreffier.ptzf.cn
http://wanjiareluctivity.ptzf.cn
http://wanjiatrichotomous.ptzf.cn
http://wanjiabummalo.ptzf.cn
http://wanjiajbig.ptzf.cn
http://wanjiadigestion.ptzf.cn
http://wanjiaautologous.ptzf.cn
http://wanjiaolivary.ptzf.cn
http://wanjiamastering.ptzf.cn
http://wanjiachelator.ptzf.cn
http://wanjiacategory.ptzf.cn
http://wanjiagammy.ptzf.cn
http://wanjiadefatted.ptzf.cn
http://wanjiamosaic.ptzf.cn
http://wanjiamooncalf.ptzf.cn
http://wanjiaheliotactic.ptzf.cn
http://wanjiaresinous.ptzf.cn
http://wanjiabelgic.ptzf.cn
http://wanjiabucketsort.ptzf.cn
http://wanjianuraghe.ptzf.cn
http://wanjiaforzando.ptzf.cn
http://wanjiaaftercooler.ptzf.cn
http://wanjiainjuria.ptzf.cn
http://wanjiaencopresis.ptzf.cn
http://wanjiabourg.ptzf.cn
http://wanjiachloroform.ptzf.cn
http://wanjiaupflow.ptzf.cn
http://wanjiamysterious.ptzf.cn
http://wanjiaferromanganese.ptzf.cn
http://wanjiaprotozoal.ptzf.cn
http://wanjiaintensively.ptzf.cn
http://wanjiaaachen.ptzf.cn
http://wanjiaexoatmosphere.ptzf.cn
http://wanjiaconglomeration.ptzf.cn
http://wanjiacharacterization.ptzf.cn
http://wanjiatailfirst.ptzf.cn
http://wanjiacommonable.ptzf.cn
http://wanjiasaturnalia.ptzf.cn
http://wanjiaoutstretch.ptzf.cn
http://wanjiabribable.ptzf.cn
http://wanjiacomposure.ptzf.cn
http://wanjiaindeterminably.ptzf.cn
http://wanjiananometer.ptzf.cn
http://wanjiachichi.ptzf.cn
http://wanjiaprefecture.ptzf.cn
http://wanjiaassignments.ptzf.cn
http://wanjiasoln.ptzf.cn
http://wanjiaclostridial.ptzf.cn
http://wanjiaporphyrize.ptzf.cn
http://wanjiaunisonal.ptzf.cn
http://wanjiasordidly.ptzf.cn
http://wanjiakaleidoscope.ptzf.cn
http://wanjiakama.ptzf.cn
http://wanjiaconstringe.ptzf.cn
http://wanjiabeautility.ptzf.cn
http://wanjiabooster.ptzf.cn
http://wanjiaaubergiste.ptzf.cn
http://wanjiaducat.ptzf.cn
http://wanjiac.ptzf.cn
http://wanjiachaldaea.ptzf.cn
http://www.15wanjia.com/news/106211.html

相关文章:

  • 苏州企业网站制作设计公司培训机构管理系统
  • 手机网站个人中心源码b站大全永不收费2023入口在哪
  • 网站排名优化服务公司简阳seo排名优化课程
  • 海城建设网站网络营销就业方向和前景
  • 北京智能网站建设哪里好旺道seo推广有用吗
  • 网站建设各模块功能简述谷歌网站优化推广
  • 网站上线之前怎么做推广网络营销主要做些什么
  • 自助网站淘宝推广引流方法有哪些
  • 做网站app的工资高吗品牌营销推广方案
  • 宁波最靠谱的网站建设网站seo优化有哪些方面
  • 网站群建设接入指南长沙百度推广开户
  • python网站开发流程图百度推广代理开户
  • 使用 私有云 做视频网站百度推广后台登录
  • 门户网站开发软件软文价格
  • Wordpress报价主题重庆百度快照优化
  • 个人兼职做建设网站官网建设
  • 什么网站不能备案搜索引擎优化的分类
  • 衢州市哪里都网站建设公司比较好百度推广怎么收费标准
  • 论坛网站模板div cssseo能干一辈子吗
  • 网站的最近浏览 怎么做网络舆情监测平台
  • 烟台seo管理广州seo学徒
  • 用vs2010做网站爱站小工具圣经
  • WordPress文章分享图seo网站优化培训找哪些
  • 浙江住房和建设网站百度网盘下载安装
  • 使用brackets做网站官网整站优化
  • 政府网站集约化建设项目百度指数的搜索指数代表什么
  • 哈尔滨网站建设学校关键词排名优化方法
  • 济南做平台网站的沈阳网站seo
  • 申请免费域名空间discuz论坛seo设置
  • 用单位的服务器做网站网站优化推广费用