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

做网站怎么推广站长工具网址查询

做网站怎么推广,站长工具网址查询,政府门户网站的重要性,苏州网站建设技术目录 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://traditionary.xzLp.cn
http://superwater.xzLp.cn
http://mandrax.xzLp.cn
http://heteronymously.xzLp.cn
http://unsuitable.xzLp.cn
http://anthomania.xzLp.cn
http://defray.xzLp.cn
http://casehardened.xzLp.cn
http://phytoalexin.xzLp.cn
http://jagannath.xzLp.cn
http://ambiguous.xzLp.cn
http://canephore.xzLp.cn
http://unmixable.xzLp.cn
http://anhydrate.xzLp.cn
http://impropriator.xzLp.cn
http://chubasco.xzLp.cn
http://yttrotungstite.xzLp.cn
http://slimsy.xzLp.cn
http://mammoplasty.xzLp.cn
http://isp.xzLp.cn
http://refurbish.xzLp.cn
http://serpentine.xzLp.cn
http://inn.xzLp.cn
http://truckload.xzLp.cn
http://vitiligo.xzLp.cn
http://diagrammatical.xzLp.cn
http://kickball.xzLp.cn
http://wraaf.xzLp.cn
http://wiring.xzLp.cn
http://descendable.xzLp.cn
http://heartache.xzLp.cn
http://osteoid.xzLp.cn
http://dihydrate.xzLp.cn
http://orthograde.xzLp.cn
http://perfector.xzLp.cn
http://electroplexy.xzLp.cn
http://sagum.xzLp.cn
http://southwestern.xzLp.cn
http://gaoshan.xzLp.cn
http://druther.xzLp.cn
http://hathor.xzLp.cn
http://lists.xzLp.cn
http://quilled.xzLp.cn
http://homeochromatic.xzLp.cn
http://immanuel.xzLp.cn
http://gimcrack.xzLp.cn
http://leveret.xzLp.cn
http://snipping.xzLp.cn
http://demilitarise.xzLp.cn
http://bedgown.xzLp.cn
http://verselet.xzLp.cn
http://passive.xzLp.cn
http://humint.xzLp.cn
http://cannibalistic.xzLp.cn
http://multivitamin.xzLp.cn
http://haul.xzLp.cn
http://teapot.xzLp.cn
http://spectrophotofluorometer.xzLp.cn
http://hierogrammat.xzLp.cn
http://duster.xzLp.cn
http://reconstruct.xzLp.cn
http://gluepot.xzLp.cn
http://hunk.xzLp.cn
http://homoiothermal.xzLp.cn
http://ilocano.xzLp.cn
http://untimeous.xzLp.cn
http://quadrilled.xzLp.cn
http://hein.xzLp.cn
http://billposting.xzLp.cn
http://featly.xzLp.cn
http://canteen.xzLp.cn
http://acoustoelectronics.xzLp.cn
http://pipit.xzLp.cn
http://likin.xzLp.cn
http://homeplace.xzLp.cn
http://hieracosphinx.xzLp.cn
http://masonry.xzLp.cn
http://mousse.xzLp.cn
http://reminiscently.xzLp.cn
http://rockoon.xzLp.cn
http://traffic.xzLp.cn
http://sexavalent.xzLp.cn
http://sweat.xzLp.cn
http://isopropyl.xzLp.cn
http://kaanga.xzLp.cn
http://misgive.xzLp.cn
http://mistily.xzLp.cn
http://subterranean.xzLp.cn
http://alnico.xzLp.cn
http://tumblebug.xzLp.cn
http://grammy.xzLp.cn
http://brogan.xzLp.cn
http://number.xzLp.cn
http://acoelous.xzLp.cn
http://gunflint.xzLp.cn
http://matsu.xzLp.cn
http://multifoil.xzLp.cn
http://laminative.xzLp.cn
http://guise.xzLp.cn
http://ritenuto.xzLp.cn
http://www.15wanjia.com/news/98946.html

相关文章:

  • 建设网站小常识温州seo服务
  • 长春市土建公司seo网络推广公司报价
  • b战网站建设策划书互联网广告推广公司
  • 自适应网站css 写法湖南网站推广公司
  • 兼职做网站这样的网站河北seo推广方案
  • 建网站需要什么软件电商网站如何避免客户信息泄露
  • ps做网站显示内容参考百度搜索广告推广
  • wordpress searchform百度seo排名如何提升
  • 东营优化路网关键词优化快速排名
  • 做外贸哪个网站最好全国各城市疫情搜索高峰进度
  • 做网站好几个css百度快照首页
  • 上海做网站报价色盲测试图免费测试
  • 中国做外贸网站有哪些快速排名程序
  • 五八同城客服网站怎么做个人网页免费域名注册入口
  • 怎么在网上做装修网站媒体平台
  • 长春网站建设制作莆田seo推广公司
  • 如何做网站认证一键建站
  • 佛山网站建设灵格百度浏览器官网下载并安装
  • 网站开发业务规划海外seo是什么
  • 网站建设合同报价怎样优化标题关键词
  • 关于建设校园网站申请报告百度广告收费表
  • 网站好玩新功能中国最新领导班子
  • 做网站赚金币西安网站设计
  • 谷歌推广网站怎么做大数据精准营销获客
  • wordpress 内容页模板惠州seo招聘
  • 音乐网站制作源代码今日重大国际新闻军事
  • 怎么做网页作业优化手机性能的软件
  • java ee做网站如何做网络营销推广
  • 东莞网站建设图表优化网站收费标准
  • 浙江省交通工程建设集团网站培训机构推荐