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

郑州定制网站游戏软件网站开发

郑州定制网站,游戏软件网站开发,wap端是电脑还是手机,深圳优化公司找高粱seo服务目录 一#xff0c;SpringBoot中读取配置文件的常用方法1.1#xff0c;使用Value读取1.2#xff0c;使用ConfigurationProperties1.3#xff0c;使用Environment1.4#xff0c;自定义配置文件读取 二#xff0c;SpringBoot部署war项目到tomcat9和启动原理 一#xff0c;… 目录 一SpringBoot中读取配置文件的常用方法1.1使用Value读取1.2使用ConfigurationProperties1.3使用Environment1.4自定义配置文件读取 二SpringBoot部署war项目到tomcat9和启动原理 一SpringBoot中读取配置文件的常用方法 1.1使用Value读取 在springBoot声明周期内可以使用Value注解从SpringBoot的默认配置文件中读取配置信息 例如在Controller中使用 // 在配置文件中读取属性名为web.images-path对应的值Value(${web.images-path})private String path;Value可以放到属性或方法上能够正常使用的前提是所在类必须在SpringBoot的生命周期内。 我们怎么把一个类放到Spring的生命周期中进行管理使用的是Component注解 因为Controller和Service本身就包含Component。所以可以直接使用。 下面是单独使用Component的例子 创建一个config包然后创建一个BootProperties package com.demo.config;import lombok.Setter; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller;Component public class BootProperties {Value(${web.images-path})public String path; } 然后在controller中写 RestController public class HelloController {Autowiredprivate BootProperties bootProperties;RequestMapping(/test5)public Object test5(){return bootProperties.path;}}使用ing类型写 package com.demo.config;import lombok.Setter; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller;Component public class BootProperties {Value(${web.images-path})public String path;Value(${server.port})public int port; }RestController public class HelloController {Autowiredprivate BootProperties bootProperties;RequestMapping(/test5)public Object test5(){return bootProperties.path ------ bootProperties.port;}}1.2使用ConfigurationProperties BootProperties类 package com.demo.config;import lombok.Setter; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller;Setter // lombok生成set方法 ConfigurationProperties(prefix server) // 配置属性类并定制前缀 Component // 因为ConfigurationProperties不能把此类放到boot容器中所以要配合Componpent使用 public class BootProperties {Value(${web.images-path})public String path;// 不使用Value注解需要保证前缀属性名全路径。还需要此属性有对应的setter方法// Value(${server.port})public int port;// 使用Value注解则需要写全路径 }controller类 RestController public class HelloController {Autowiredprivate BootProperties bootProperties;RequestMapping(/test5)public Object test5(){return bootProperties.path ------ bootProperties.port;}}1.3使用Environment Environment是SpringCore中的一个用于读取配置文件的类将此类使用Autowired注入到类中就可以使用它的getProperty方法来获取某个配置项的值 RestController public class HelloController {Autowiredprivate Environment environment;RequestMapping(/test7)public Object test7(){return environment.getProperty(server.port);}}1.4自定义配置文件读取 使用之前的知识来理解下面的代码。 主要添加新的注解PropertySource 创建一个config包然后创建一个SysProperties package com.demo.config;import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component;ConfigurationProperties(prefix sys) Component PropertySource(classpath:sys.properties) Getter Setter public class SysProperties {private String param1;private String param2; }controller类 RestController public class HelloController {Autowiredprivate SysProperties sysProperties;RequestMapping(/test6)public Object test6(){return sysProperties.getParam1()sysProperties.getParam2();}}二SpringBoot部署war项目到tomcat9和启动原理 创建一个新项目 在添加个模块 然后在pom中添加依赖 packagingwar/packagingparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.0.1.RELEASE/version/parentdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency/dependenciesbuildfinalNamepasserby-war/finalNamepluginsplugin!-- 打包插件 --groupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build然后添加controller类和一个启动类 然后随便在Controller类里面加个方法 package com.demo.controller;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class Controller {RequestMapping(/demo01)public Object demo01(){return hello,war;} } 开始打包 在文件夹中找到这个位置 找到后把刚打的war包复制下来 然后在到你Tomcat的位置 把war包复制到里面 然后打开bin目录 在里面找到startup.bat这个 打开等他运行完 然后在打开你刚才把war包粘贴的那个文件夹 现在就好了打开浏览器试试 有什么不理解的可以私信
http://wiki.neutronadmin.com/news/480361/

相关文章:

  • 网站都有什么语言wordpress 免费采集
  • 网站工程师培训学校做网站商城怎么样
  • 临清做网站推广北京网站建设qq群
  • 网站建设费应该怎样入账5个制造企业电子商务网站
  • 网站建设公司如何发展如何进入wordpress
  • 网站建设任务和标准黄浦做网站公司
  • 服务器建设网站软件网站 无限下拉
  • 17网站一起做网店东莞网络营销课程思政
  • 网站模板购买 优帮云查企业下载什么软件
  • 专业做网站照片湖南省住房城乡建设厅网站
  • flash网站开源扬州天达建设集团有限公司网站
  • 今天搜索引擎优化排名技巧
  • wp网站建设教程周口航迪科技网站建设公司怎么样
  • 厦门网站建设网页设计江苏两学一做网站
  • 网站301重定向代码大方县住房城乡建设局网站
  • 做网站后期续费是怎么算的自己的网站怎样做优化
  • 合肥网站的建设一个网页多少钱合适
  • 淘宝上网站开发退款网站建设方法叁金手指下拉丶
  • 阿里巴巴网站怎么做全屏大图想做苗木生意网站怎么怎么做
  • 视频网站亏损也做廊坊网站建设技术外包
  • 北京做网站推广seo网站建设的软件叫啥
  • 网页制作素材库哪个网站口碑营销策略
  • 怎么做一个网站的logo设计图绍兴seo推广
  • wordpress 连接微信大连seo网站推广
  • 武安做网站公司招聘信息
  • aaaa景区网站建设标准公司公众号怎么制作
  • 手机视频做动画视频在线观看网站交互式网站开发技术包括
  • 沙田网站仿做建设银行公积金预约网站
  • 邢台地区网站建设北京十大影视公司
  • 可以做护考题目的网站海安网页设计