自己的网站怎么优化,国际网站设计,定制开发小程序,响应式网站建设服务首先我的博客记理论知识很少#xff0c;大家对spring boot、spring cloud 、分布式 、微服务什么的一点概念都没有的还请先去百度看看理论#xff0c;知道了是做什么用的#xff0c;然后再写下demo ,这样学起来才没有那么迷糊#xff01; 我一般写下的demo都是我踩了很多坑… 首先我的博客记理论知识很少大家对spring boot、spring cloud 、分布式 、微服务什么的一点概念都没有的还请先去百度看看理论知道了是做什么用的然后再写下demo ,这样学起来才没有那么迷糊 我一般写下的demo都是我踩了很多坑或者说很多人在其他地方写下的demo搬过来根本运行不起来然后我经过处理和查询整理了一下 方便我以后再回来查找也方便有些小伙伴入门的demo! 我就简略的介绍一个这个demo;就是spring cloud 中的一个注册服务器 、注册管理中心 会自动监控 这个demo是我从官网上面找下来的然后注释了一些用不上的代码和配置 我这里采用的idea编辑器 第一步我们建立一个spring boot项目 如下图一直next.......最后Finish 第二步修改maven的pom文件文件已经给你们整理好了如下 ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersion!--描述这个POM文件是遵从哪个版本的项目描述符。--groupIdcom.example/groupIdartifactIddemo/artifactIdversion0.0.1-SNAPSHOT/versionpackagingjar/packagingnamedemo/namedescriptiondemo project for Spring Boot/descriptionparent!--父级依赖继承--groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.2.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentdependencies!--引入依赖--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-config/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependencies!--声明依赖如果dependencies中没有声明版本就会来这里面找--dependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversionFinchley.BUILD-SNAPSHOT/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementproperties!--定义的标签属性可以在其他地方读取--project.build.sourceEncodingUTF-8/project.build.sourceEncodingstart-classcom.example.demo.DemoApplication/start-classjava.version1.8/java.version!-- docker.image.prefixspringcloud/docker.image.prefix--/propertiesbuildplugins!-- plugingroupIdcom.spotify/groupIdartifactIddocker-maven-plugin/artifactIdversion0.2.3/versionconfigurationbaseImageopenjdk:8-jre-alpine/baseImageimageName${docker.image.prefix}/${project.artifactId}/imageNameexposes8761/exposesentryPoint[java, -Djava.security.egdfile:/dev/./urandom, -jar, /${project.build.finalName}.jar]/entryPointresourcesresourcetargetPath//targetPathdirectory${project.build.directory}/directoryinclude${project.build.finalName}.jar/include/resource/resources/configuration/plugin--!-- plugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdlt;!ndash; defined in spring-cloud-starter-parent pom (as documentation hint),but needs to be repeated here ndash;gt;configurationrequiresUnpackdependencygroupIdcom.netflix.eureka/groupIdartifactIdeureka-core/artifactId/dependencydependencygroupIdcom.netflix.eureka/groupIdartifactIdeureka-client/artifactId/dependency/requiresUnpack/configuration/plugin--!-- plugingroupIdpl.project13.maven/groupIdartifactIdgit-commit-id-plugin/artifactIdconfigurationfailOnNoGitDirectoryfalse/failOnNoGitDirectory/configuration/pluginpluginlt;!ndash;skip deploy (this is just a test module) ndash;gt;artifactIdmaven-deploy-plugin/artifactIdconfigurationskiptrue/skip/configuration/plugin--/plugins/build!-- lt;!ndash;相当于配置远程仓库ndash;gt;repositoriesrepositoryidspring-snapshots/idnameSpring Snapshots/nameurlhttps://repo.spring.io/libs-snapshot/urllt;!ndash;是否自动更新ndash;gt;snapshotsenabledtrue/enabled/snapshots/repositoryrepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/libs-milestone/urlsnapshotsenabledfalse/enabled/snapshots/repositoryrepositoryidspring-releases/idnameSpring Releases/nameurlhttps://repo.spring.io/libs-release/urlsnapshotsenabledfalse/enabled/snapshots/repository/repositorieslt;!ndash;插件仓库ndash;gt;pluginRepositoriespluginRepositoryidspring-snapshots/idnameSpring Snapshots/nameurlhttps://repo.spring.io/libs-snapshot-local/urlsnapshotsenabledtrue/enabled/snapshots/pluginRepositorypluginRepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/libs-milestone-local/urlsnapshotsenabledfalse/enabled/snapshots/pluginRepository/pluginRepositories--/project 以上的pom文件你复制进去了会发现很多注释掉了。先别管 第三步修改 application.properties文件内容如下 server.port3333eureka.instance.hostnamelocalhost
#不要向注册中心注册自己
eureka.client.register-with-eurekafalse
#禁止检索服务
eureka.client.fetch-registryfalse
eureka.client.service-url.defaultZonehttp://${eureka.instance.hostname}:${server.port}/eureka 第四步在启动类上加上这个注解EnableEurekaServer package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;EnableEurekaServer
SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}
} 到了这一步所有的配置和代码已经写完了 注意如果你的项目现在启动不起来那就把pom文件的注释全部放开会自动从配置的仓库里面下载jar包 一切正常后我们通过main方法启动通过上面的配置我们打开浏览器访问 http://localhost:3333 会出现如下界面 转载于:https://www.cnblogs.com/qq376324789/p/10045078.html