中山英文网站建设手表商城网站建设方案

web/2025/9/28 10:50:44/文章来源:
中山英文网站建设,手表商城网站建设方案,百度福州分公司,菏泽建设局网站SpringBoot用来简化Spring应用开发#xff0c;约定大于配置#xff0c;去繁从简#xff0c;是由Pivotal团队提供的全新框架。其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置#xff08;有特殊需求可以添加自己的配置覆盖默认配…SpringBoot用来简化Spring应用开发约定大于配置去繁从简是由Pivotal团队提供的全新框架。其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置有特殊需求可以添加自己的配置覆盖默认配置从而使开发人员不再需要定义样板化的配置。SpringBoot可以看成是J2EE的一站式解决方案。 一、SpringBoot 的优点 【1】快速创建独立运行的Spring项目以及与主流框架集成。 【2】使用嵌入式的Servlet容器应用无需打成war包可以打成jar包通过java -jar的方式直接运行。 【3】starters启动器自动依赖与版本控制。 【4】大量的自动配置简化开发也可以修改默认值。 【5】无需配置XML无代码生成开箱即用。 【6】准生产环境的运行时应用监控。 【7】与云计算的天然集成。 二、解决微服务部署和运维难的问题Spring Boot 如上的流程依次为 搭建项目 构建连接 批处理 三、Spring Boot 入门项目 HelloWorld也可以参考五快速创建一个 SpringBoot项目 【1】准备环境 为Maven的settings.xml配置文件的profiles标签添加如下信息 profile idjdk-1.8/id activationactiveByDefaulttrue/activeByDefaultjdk1.8/jdk /activation propertiesmaven.compiler.source1.8/maven.compiler.sourcemaven.compiler.target1.8/maven.compiler.targetmaven.compiler.compilerVersion1.8/maven.compiler.compilerVersion /properties /profile【2】将IDEA的 Maven更换为我们自己本地安装的Maven。自行百度更换创建一个maven工程[jar]在pom.xml中导入如下依赖 parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.0.RELEASE/version /parent dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency /dependencies【3】编写一个主程序启动SpringBoot应用 SpringBootApplication public class Hello {public static void main(String[] args) throws Exception {//启动spring应用SpringApplication.run(Hello.class, args);} }【4】编写相关的Controller、Service类 Controller public class HelloController {ResponseBodyRequestMapping(/hello)public String hello(){return hello world!;} }【5】运行主测试程序。简化部署应用可以将应用打包成一个可执行的jar包通过Maven Projects中 的package双击即可。生成jar的位置默认在项目的target目录下的“项目名称.jar”文件。运行jar在命令行可以通过 “java -jar jar文件名.jar” 命令运行项目。 buildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins /build四、Hello World 探究POM文件 【1】父项目[spring-boot-starter-parent] parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.0.RELEASE/version /parent【2】进入spring-boot-starter-parent发现它还有一个父项目 parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion2.0.0.RELEASE/versionrelativePath../../spring-boot-dependencies/relativePath /parent【3】进入spring-boot-dependencies后发现如下信息与之前我们创建的分布式项目继承的Maven父项目功能是一样的用来管理所有jar包依赖的版本。称为SpringBoot的版本仲裁中心以后我们导入依赖默认是不需要写版本没有在dependencies里面管理的依赖需要声明版本号 propertiesactivemq.version5.15.3/activemq.versionantlr2.version2.7.7/antlr2.versionappengine-sdk.version1.9.62/appengine-sdk.versionartemis.version2.4.0/artemis.versionaspectj.version1.8.13/aspectj.versionassertj.version3.9.1/assertj.version... 此处省略 .../ /properties【4】启动器[spring-boot-starter-web] dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId /dependencyspring-boot-starter-webspring-boot-starter指spring-boot场景启动器进入官网可以到有许多场景启动器简单点说就是通过此功能将相关jar包给组合在起来我们使用时只需要引入一个Web Starter就可以轻松搞定。Spring Boot将所有的功能场景都抽取出来做成一个个的 starters启动器只需要在项目里面引入这些starter相关场景所有依赖都会导入进来。要用什么功能就导入什么场景启动器。 点击web右边的pom可以看到SpringBoot为我们依赖的其它jar包帮我们导入了web模块正常运行所依赖的所有组件。如下 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-tomcat/artifactId/dependencydependencygroupIdorg.hibernate/groupIdartifactIdhibernate-validator/artifactId/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactId/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-web/artifactId/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactId/dependency /dependencies【5】主程序类Java类SpringBootApplication此注解声明的类是SpringBoot的主配置类SpringBoot就应该运行这个类的main方法来启动SpringBoot。 //ImportResource(locations{classpath:bean.xml}) //SpringBootApplication 来标注一个主程序类说明这是一个SpringBoot应用 SpringBootApplication public class HellowordQuickStartApplication {public static void main(String[] args) {/*SpringBoot应用启动项HellowordQuickStartApplication.class 参数必须是用SpringBootApplication注解修饰的类*/SpringApplication.run(HellowordQuickStartApplication.class, args);} }SpringBootApplication主要由SpringBootConfiguration/EnableAutoConfiguration/ComponentScan组成 Target(ElementType.TYPE) Retention(RetentionPolicy.RUNTIME) Documented Inherited SpringBootConfiguration EnableAutoConfiguration ComponentScan(excludeFilters {Filter(type FilterType.CUSTOM, classes TypeExcludeFilter.class),Filter(type FilterType.CUSTOM, classes AutoConfigurationExcludeFilter.class) }) public interface SpringBootApplication {SpringBootConfiguration标注在某个类上表示此类是一个SpringBoot的配置类。由以下注解组合形成配置类 配置文件配置类也是容器的一个组件底层由Component等等组成。 Target({ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented Configuration //表示此类是一个配置类 是spring的一个组件 public interface SpringBootConfiguration {EnableAutoConfiguration开启自动配置功能。也是一个组合注解由以下注解组成部分重要注解 AutoConfigurationPackage Import(AutoConfigurationImportSelector.class) public interface EnableAutoConfiguration {AutoConfigurationPackage自动依赖相关的配置包也是一个组合注解主要由import等注解组合 Import({Registrar.class})//给容器中导入一个组件导入的组件由此组建决定。 public interface AutoConfigurationPackage {进入Import(Registrar.class)中的Registrar类中通过断点可以查看到我注释的一些信息。 static class Registrar implements ImportBeanDefinitionRegistrar, DeterminableImports {Registrar() {}//registerBeanDefinitions方法中的metadata可以查看到我们启动类使用的注解 SpringBootApplicationpublic void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {AutoConfigurationPackages.register(registry, new String[]{(new AutoConfigurationPackages.PackageImport(metadata)).getPackageName()});}//new AutoConfigurationPackages.PackageImport(metadata) 可以解析出我们当前主启动所在的package包public SetObject determineImports(AnnotationMetadata metadata) {return Collections.singleton(new AutoConfigurationPackages.PackageImport(metadata));} }Import(Registrar.class)作用将主配置类的所在包以及下边所有子包里面的所有组件扫描到Spring容器中。这也就能理解为什么会自动扫描我们写的Controller类了。 Import(AutoConfigurationImportSelector.class)进入AutoConfigurationImportSelector.class类中查看如下方法 public String[] selectImports(AnnotationMetadata annotationMetadata) {if(!this.isEnabled(annotationMetadata)) {return NO_IMPORTS;} else {try {AutoConfigurationMetadata autoConfigurationMetadata AutoConfigurationMetadataLoader.loadMetadata(this.beanClassLoader);AnnotationAttributes attributes this.getAttributes(annotationMetadata);// 主要用到的是 这个 configurations 后面会有重点说明ListString configurations this.getCandidateConfigurations(annotationMetadata, attributes);configurations this.removeDuplicates(configurations);configurations this.sort(configurations, autoConfigurationMetadata);SetString exclusions this.getExclusions(annotationMetadata, attributes);this.checkExcludedClasses(configurations, exclusions);configurations.removeAll(exclusions);configurations this.filter(configurations, autoConfigurationMetadata);this.fireAutoConfigurationImportEvents(configurations, exclusions);return StringUtils.toStringArray(configurations);} catch (IOException var6) {throw new IllegalStateException(var6);}} }这是导入组件的选择器方法将所有需要导入的组件以全类名的方式返回这些组件最终被添加到容器中。其中ListString configurations会给容器中导入非常多的自动配置类[xxxAutoConfiguration]就是给容器中导入这个场景需要的所有组件并配置好这些组件。有了自动配置类免去了我们手动编写配置注入功能组件等的工作自动配置类共109个如下部分所示 ☹ 那么我们就有疑问这些自动配置类都是从哪里来的 进入这个方法this.getCandidateConfigurations(annotationMetadata, attributes) protected ListString getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {// *** 后边需要了解的方法 ***//SpringFactoriesLoader.loadFactoryNamesEnableAutoConfiguration.class,classLoader;ListString configurations SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());Assert.notEmpty(configurations, No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.);return configurations; }进入SpringFactoriesLoader.loadFactoryNamesEnableAutoConfiguration.class,classLoader方法具体注释说明 public static ListString loadFactoryNames(Class? factoryClass, Nullable ClassLoader classLoader) {//org.springframework.context.ApplicationContextInitializerString factoryClassName factoryClass.getName();return (List)loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList()); } private static MapString, ListString loadSpringFactories(Nullable ClassLoader classLoader) {MultiValueMapString, String result (MultiValueMap)cache.get(classLoader);if(result ! null) {return result;} else {try {//通过类加载器classLoader获取META-INF/spring.factories也就是配置了109个自动配置类的文件 资源EnumerationURL urls classLoader ! null?classLoader.getResources(META-INF/spring.factories):ClassLoader.getSystemResources(META-INF/spring.factories);LinkedMultiValueMap result new LinkedMultiValueMap();while(urls.hasMoreElements()) {URL url (URL)urls.nextElement();UrlResource resource new UrlResource(url);//将urls 当做一个properties配置文件Properties properties PropertiesLoaderUtils.loadProperties(resource);Iterator var6 properties.entrySet().iterator();while(var6.hasNext()) {Entry?, ? entry (Entry)var6.next();//将META-INF/spring.factories文件中的EnableAutoConfiguration下的配置进行加载 如下图所示ListString factoryClassNames Arrays.asList(StringUtils.commaDelimitedListToStringArray((String)entry.getValue()));result.addAll((String)entry.getKey(), factoryClassNames);}}cache.put(classLoader, result);return result;} catch (IOException var9) {throw new IllegalArgumentException(Unable to load factories from location [META-INF/spring.factories], var9);}} }我们进入其中一个自动配置类中看看SpringBoot是不是真的帮我们已经配置好了一些属性[WebMvcAutoConfiguration] //这里我就摘出一些重要的配置来帮我我们观察即可。 Configuration public class WebMvcAutoConfiguration {BeanConditionalOnMissingBean/** 视图解析器 SpringBoot中的所有配置文件都是.java形式方法的名字就是以前xml中的id。等等都是用注解表示的这个我们后面会重点说明这里就先了解一下*///我们可以看到SpringBoot已经帮我们配置好了视图解析器 等等一些功能 我们直接使用就好public InternalResourceViewResolver defaultViewResolver() {InternalResourceViewResolver resolver new InternalResourceViewResolver();resolver.setPrefix(this.mvcProperties.getView().getPrefix());resolver.setSuffix(this.mvcProperties.getView().getSuffix());return resolver;} }总结 SpringBoot在启动的时候从类路径下的META-INF/spring.factories中获取EnableAutoConfiguration指定的值将这些值作为自动配置类导入到容器中自动配置类就生效帮我们进行自动配置工作。如此一来就具有我们在SSM等环境下写了一大堆配置文件后才具有的功能。而这些所有配置文件都在spring-boot-autoconfigure-2.0.0.RELEASE.jar 中。 五、使用 Spring Initializer 快速创建 Spring Boot 项目 注意Artifact中不能大小写混合使用。 通过需求选择starts例如选择Web。 我们就会发现pom.xml文件中就会自动配置了我们引入的starts。 !-- 摘取一部分 -- parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.0.RELEASE/versionrelativePath/ !-- lookup parent from repository -- /parentpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingjava.version1.8/java.version /properties dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional/dependency /dependencies添加controller层 新注解RestController ResponseBody与Controller的合体 //这个类的所有方法返回的数据直接写给浏览器如果是对象转为JSON //ResponseBodyController RestController public class HelloWordController {RequestMapping(/hello)public String hello(){return hell;} }优点 默认生成的SpringBoot项目我们只需要编写自己的逻辑。默认生成的Resources配置文件的目录结构 【1】static保存所有的静态资源。 [js/css/image] 【2】templates保存所有的模板页面[SpringBoot默认jar包使用嵌入式的 Tomcat默认不支持JSP页面]但可以使用模板引擎。freemarker、thymeleaf 【3】application.propertiesSpringBoot应用的配置文件。默认的配置都在此文件可以修改。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/83291.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

泰州外贸网站建设国家商标局商标查询网

目录 1 软件架构设计导论2 HR角度看架构师3 软件架构设计概述4 顶级大师眼中的架构5 建筑中的架构师6 软件架构的发展阶段7 软件架构的意义8 架构是项目干系人进行交流的手段9 架构有助于循序渐进的原型设计10 架构是设计决策的体现11 架构明确系统设计约束条件12 架构与组织结…

制作网站设计的总结wordpress无法连接app

本专栏主要是提供一种国产化图像识别的解决方案,专栏中实现了YOLOv5/v8在国产化芯片上的使用部署,并可以实现网页端实时查看。根据自己的具体需求可以直接产品化部署使用。 B站配套视频:https://www.bilibili.com/video/BV1or421T74f 背景…

电子商务网站建设 考卷在线制作图网站

直接使用lowpass, highpass, bandpass等函数时会自动对filtering带来的时延给予补偿.但是对于自己设计的filter, 利用filt来进行滤波的话就会带来时延. 可以使用函数 grpdelay(filter,N,Fs) 来查看.对于FIR filter, 造成的时延对于不同的频率相应是一致的, 那么直接移动滤波后的…

淄博服装网站建设十大互联网装修平台

SLF4J是一个非常流行的日志记录外观,但是,就像我们使用的所有库一样,我们有可能以错误的方式或至少以非最佳方式使用它。 在本教程中,我们将列出常见的日志记录错误以及如何使用FindBugs检测到它们。 我们还将在相关时提及PMD和S…

珠海网站建设网站品质好的四字词语

目录 一、弧度转角度1、计算公式2、主要函数3、示例代码4、结果展示二、角度转弧度1、计算公式2、主要函数3、示例代码4、结果展示三、归一化到(-PI,PI)1、主要函数<

绵阳网站关键字优化微信视频号怎么推广引流

2024年4月9号PMP每日三题含答案 1.在执行一个潜艇现代化项目期间&#xff0c;客户要求安装新的潜望镜。项目经理必须怎么做&#xff1f; A.检查可行性&#xff0c;准备预算&#xff0c;并获得变更请求批准 B.执行实施整体变更控制过程&#xff0c;获得预算批准&#xff0c;并执…

检察院网站建设情况成都网站建设设计公司排名

Google Guava项目是每个Java开发人员都应该熟悉的库的集合。 Guava库涵盖I / O&#xff0c;集合&#xff0c;字符串操作和并发性。 在这篇文章中&#xff0c;我将介绍Monitor类。 Monitor是一种同步构造&#xff0c;可以在使用ReentrantLock的任何地方使用。 在任何时候&#x…

单页面网站入侵wordpress一直维护

一&#xff1a;问题 有两个规模相同的数组&#xff0c;两个数组相同位置的元素一一对应&#xff0c;现在要将两数组的元素同时打乱顺序&#xff0c;并且乱序后的两数组对应位置元素要保持乱序前的对应关系。 二&#xff1a;方法 采用randperm&#xff08;&#xff09;函数&a…

外贸平台哪个网站最好发布程序后网站有很多

理论知识&#xff1a; &#xff08;1&#xff09;状态机简写为FSM&#xff08;Finite State Machine&#xff09;&#xff0c;也称为同步有限状态机。同步是指状态的变化都是在时钟的边沿发送变化&#xff0c;有限值得是状态的个数是可数的。 &#xff08;2&#xff09;分类&…

有赞微商城是什么seo推广和百度推广的区别

摘要&#xff1a; 昇思MindSpore支持checkpoint和MindIR两种形式的模型保存和加载。 保存和加载模型&#xff0c;便于微调fine-tune和后续的模型推理与部署。 一、环境准备 安装minspore模块 !pip uninstall mindspore -y !pip install -i https://pypi.mirrors.ustc.edu.c…

南京网络推广平台seo顾问张智伟

Acme.sh 是一个开源的脚本&#xff0c;能够从 ZeroSSL、Let’s Encrypt 等证书颁发机构&#xff08;CA&#xff09;获取免费的 HTTPS 证书。该脚本特别简单易用&#xff0c;并且支持多种验证方式。下面将详细介绍使用 Acme.sh 生成、安装和更新证书的各个步骤。 Github地址 使用…

网站开发用框架开发的优缺点淘客网站如何做能加快收录

IE trident Firefox Gecko Google chrome Webkit/blink Safar i Webkit Opera presto转载于:https://www.cnblogs.com/codezhao/p/10451030.html

企业网站建设多少钱网站和软件有什么区别

本文介绍在CentOS 7操作系统上安装Semaphore的方法&#xff0c;安装完后就可以使用Semaphore来管理Ansible Web UI了。一、安装MariaDB数据库和git 2.x参考文章1、安装MariaDB数据库参考文章2、安装git 2.x确认git版本&#xff1a;$ git --versiongit version 2.16.5二、安装An…

网站后台生成文章很慢游戏制作公司

目录 题目描述 输入 输出 样例输入 Copy 样例输出 Copy code 题目描述 输入3个整数&#xff0c;输出绝对值最大的那个数。 输入 输入包含3个int范围内的整数&#xff0c;用空格隔开。 输出 输出三个数中绝对值最大的数&#xff0c;单独占一行。若绝对值最大的数不唯…

响应式网站模板html什么网站需要数据库

一、&#x1f4dd;功能介绍 基于SpringBoot Vue汽车租赁系统 角色&#xff1a;管理员、普通管理员、用户 管理员&#xff1a;管理员进入主页面&#xff0c;主要功能包括对系统首页、个人中心、用户管理、普通管理员管理、汽车类别管理、汽车信息管理、租车订单管理、取消订单管…

美术馆网站建设网站开发人员的职能

反思: 我考得最炸的一次 怎么说呢?简单的两个题0分,稍难(我还不敢说难,肯定又有人喷我)42分 前10分钟看T1,不会,觉得不可做,完全不可做,把它跳了 最后10分钟看T1,发现一个有点用的性质,仍然认为不可实现 0分 所以T1是什么样的难题呢 即使暴力也有60分,但我楞没想出来暴力怎么打…

模板网站的建设软件开发过程模型

1. 位图结构的实现 /*** 位图数据类型 <br />* 位图以字节的一位为单位进行元素的操作&#xff0c;但是位运算以一个字节整体为运算单位&#xff0c;因此代码中以 bytes[index] 进行运算。* 位图元素的添加即找到相应的位置&#xff0c;将其置为1&#xff0c;实现时将该…

集团网站设计专业团队建设网站需要什么软件

说明&#xff1a;首先我的nacos安装是2.1.1版本&#xff0c;请注意版本问题。另外启动时用dubbo的话必须先启动服务提供者再启动服务使用者&#xff0c;否则会报错&#xff0c;同时也必须开放三个端口&#xff1a;8848&#xff0c;9848&#xff0c;9849 java.lang.IllegalStat…

品牌微信网站定制007工作制

CentOS 6 是 CentOS 项目的一个主要版本。CentOS&#xff08;Community ENTerprise Operating System&#xff09;是一个基于开源的 Linux 发行版&#xff0c;它主要从源代码构建自 Red Hat Enterprise Linux&#xff08;RHEL&#xff09;。CentOS 6 代表了该操作系统的第六个主…