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

做论坛和做网站有什么区别怎么用自己的电脑建设网站

做论坛和做网站有什么区别,怎么用自己的电脑建设网站,郑州seo规则,站长工具seo综合查询可以访问在上一篇文章中#xff0c;我们已经了解了一个starter实现自动配置的基本流程#xff0c;在这一小结我们将复现上一过程#xff0c;实现一个自定义的starter。 先来分析starter的需求#xff1a; 在项目中添加自定义的starter依赖#xff0c;自动在Spring中加载starter中的… 在上一篇文章中我们已经了解了一个starter实现自动配置的基本流程在这一小结我们将复现上一过程实现一个自定义的starter。 先来分析starter的需求 在项目中添加自定义的starter依赖自动在Spring中加载starter中的Bean从application.properties中加载指定配置创建项目 先创建一个名为starter的项目。?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns: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/modelVersiongroupIdtop.ninwoo/groupIdartifactIddemo-starter/artifactIdversion1.0.0/versionpackagingjar/packagingdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot/artifactIdversion2.1.6.RELEASE/version/dependency/dependencies /project 在resources中创建一个META-INF的目录并在目录中创建一个spring.factories。在这个配置中我们只设置一个EnableAutoConfiguration项并且对应只设置一个DemoAutoConfig配置类。org.springframework.boot.autoconfigure.EnableAutoConfigurationtop.ninwoo.config.DemoAutoConfig 创建DemoAutoConfig配置类 package top.ninwoo.config;import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration EnableConfigurationProperties(DemoStarterProperties.class) public class DemoAutoConfig {BeanDemoBean demoBean() {return new DemoBean();} } 这个配置类我们主要使用了Configuration和EnableConfigurationProperties两个注解。EnableConfigurationProperties启用一个ConfigurationProperties。创建ConfigurationProperties对应的DemoStarterProperties package top.ninwoo.config;import org.springframework.boot.context.properties.ConfigurationProperties;ConfigurationProperties(prefix top.ninwoo.demo) public class DemoStarterProperties {private String name default;private int age 0;public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;} } 创建一个ConfigurationProperties类。这个类主要用来从application.properties中读取配置项并自动设置到相对应的字段上。创建一个测试用Bean并使用ConfigurationProperties类中的信息。 起初这里有个疑惑不知道如何使用这个ConfigurationProperties类。不过在spring中最常见的就是Bean我们可以大胆的猜测通过ConfigurationProperties注释的类将自动在Spring容器中自动创建一个Bean。而我们在使用的时候就通过普通的bean注入方式便可以使用ConfigurationProperties类中的信息。所以我们这样创建一个测试Bean package top.ninwoo;import javax.annotation.Resource;public class DemoBean {ResourceDemoStarterProperties properties;public String getName() {return properties.getName();}public String getAge() {return getAge();} }同时在DemoAutoConfig中使用Bean注解创建一个Bean。到这里我们的starter就创建完成了。通过mvn打包或者创建同一个父项目的不同子Module的方式我们可以进行测试这个starter是否生效。 创建测试类 测试类使用一个spring boot web项目来完成主要创建了一个RestController并通过RestController获取Spring上下文中注册的bean names和starter中的测试Bean。 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns: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/modelVersiongroupIdtop.ninwoo/groupIdartifactIdspringboot-demo/artifactIdversion1.0.0/versionparentartifactIdspring-boot-starter-parent/artifactIdgroupIdorg.springframework.boot/groupIdversion2.1.6.RELEASE/version/parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdtop.ninwoo/groupIdartifactIddemo-starter/artifactIdversion1.0-SNAPSHOT/version/dependency/dependencies /project 在pom文件中我们添加了刚刚实现的starter。 RestController: RestController public class IndexController implements ApplicationContextAware {ApplicationContext ctx null;ResourceDemoBean demoBean;RequestMapping(/getList)public String[] getBeanNames() {return ctx.getBeanDefinitionNames();}RequestMapping(/getDemoBean)public String demoBean() {return demoBean.getName();}Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {ctx applicationContext;} }SpringBoot启动类 MainApp: package top.ninwoo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class MainApp {public static void main(String[] args) {SpringApplication.run(MainApp.class, args);} } 我们可以看到与正常的一个web项目相比我们只是添加了一个依赖而并没有修改启动类。 测试 访问127.0.0.1:8080/getList接口我们可以看到最后的几个bean Names是 ...,top.ninwoo.config.DemoAutoConfig,demoBean,top.ninwoo.demo-top.ninwoo.config.DemoStarterProperties] 这证明通过注入我们starter依赖已经在Spring的上下文创建了starter配置类中的Bean。 在没有设置application.properties时直接访问http://127.0.0.1:8080/getDemoBean可以获取到测试用的Bean实例中默认的参数配置default. 添加application.properties top.ninwoo.demo.namejoliu 重启项目再次访问该接口发现测试用的Bean实例对应的属性已经安装配置类中的参数进行设置返回了joliu。 小结 到这里我们可以说已经了解了开发一个SpringBoot Starter最基本的流程我们可以尝试在我们日常的项目中开发这样的starter。 转载于:https://www.cnblogs.com/NinWoo/p/11305650.html
http://www.zqtcl.cn/news/784536/

相关文章:

  • 注册或者浏览社交类网站时不恰当威宁做网站
  • 国外的电商网站有哪些方面沈阳医疗网站制作
  • 那个企业网站是用vue做的网站频道运营怎么做
  • 英语培训学校网站怎么做网站建建设公司和网络自建
  • 无法访问iis网站网站吸引客户
  • 郑州企业网站排名优化wordpress指定文章
  • 南京 网站开发宿州网站建设工作室
  • 龙海市城乡规划建设局网站河南郑州哪里可以做公司网站
  • 网站正能量晚上不用下载进入免费成都网站制作方案
  • 宝安做棋牌网站建设哪家公司便宜jsp网站搭建
  • 英文网站建设方法深圳信用网
  • ip查询网站用织梦后台修改网站logo
  • 网站编辑信息怎么做茶叶网站建设策划书ppt
  • 网站建设费摊销几年嵌入式软件开发用什么语言
  • 网站备案 后期商业设计网站
  • 网站负责人半身照国际公司和跨国公司
  • 网站的组成友情下载网站
  • 做视频课程网站中职网站建设
  • seo整站优化服务盗图来做网站
  • 网站服务器基本要素有哪些交易网站的建设规划
  • 网站开发源代码mvc山东网站推广
  • 深圳建网站兴田德润团队织梦的网站模板免费吗
  • 手机响应式网站怎么做图书馆建设网站注意点
  • 白云做网站要多少钱wordpress指定分类子类
  • 侧导航网站济南网上房地产
  • 做得比较好的公司网站自己可以学做网站吗
  • 陕西省两学一做网站产品推广方案
  • 做网站ps文字有锯齿网站建设项目管理基本要求
  • 大连网站制作的网络科技公司取名创意
  • 哈尔滨企业网站建站推荐专业微网站营销