一、配置文档application.properties的基本使用

二、绑定对象bean调用

三、参数间引用

 四、使用自定义新建的配置文件

五、配置文件优先级

六.随机值配置

七.外部配置-命令行参数配置

八.springboot使用spring.profiles.active添加多个properties或者yml配置文件

.springboot 加载自定义yml文件

一、配置文档配置项的调用(application.properties可放在resources,或者resources下的config文件夹里)

  1. package com.my.study.controller;
  2.  
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.boot.context.properties.ConfigurationProperties;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RestController;
  8.  
  9. import com.my.study.model.Student;
  10.  
  11. @RestController
  12. @SpringBootApplication
  13. @RequestMapping("/user")
  14. public class UserController {
  15.  
  16. @Value("${test.stuName}")
  17. private String stuName;
  18.  
  19. @Value("${test.stuSex}")
  20. private String stuSex;
  21.  
  22. @RequestMapping("/test")
  23. public Object sayHello() {
  24.  
  25. Student student = new Student();
  26. student.setStuName(stuName);
  27. student.setStuSex(stuSex);
  28.  
  29. return student ;
  30. }
  31.  
  32. }

启动后在浏览器直接输入http://localhost:18080/user/test,就直接打印出配置文件中的配置内容。

二、绑定对象bean调用

有时候属性太多了,一个个绑定到属性字段上太累,官方提倡绑定一个对象的bean,这里我们建一个ConfigBean.java类,顶部需要使用注解@ConfigurationProperties(prefix = “test”)来指明使用哪个

注意:类中一定要有get set 和无参的构造方法方法,否则参数无法绑定,

  1. package com.my.study.model;
  2.  
  3. import org.springframework.boot.context.properties.ConfigurationProperties;
  4.  
  5. @ConfigurationProperties(prefix ="test")
  6. public class ConfigBean {
  7.  
  8. private String stuName;
  9.  
  10. private String stuSex;
  11.  
  12. /* (non-Javadoc)
  13. * @see java.lang.Object#toString()
  14. */
  15. @Override
  16. public String toString() {
  17. return "ConfigBean [stuName=" + stuName + ", stuSex=" + stuSex + "]";
  18. }
  19.  
  20. /**
  21. * @return the stuName
  22. */
  23. public String getStuName() {
  24. return stuName;
  25. }
  26.  
  27. /**
  28. * @param stuName the stuName to set
  29. */
  30. public void setStuName(String stuName) {
  31. this.stuName = stuName;
  32. }
  33.  
  34. /**
  35. * @return the stuSex
  36. */
  37. public String getStuSex() {
  38. return stuSex;
  39. }
  40.  
  41. /**
  42. * @param stuSex the stuSex to set
  43. */
  44. public void setStuSex(String stuSex) {
  45. this.stuSex = stuSex;
  46. }
  47.  
  48. }

此时配置完还需要在spring Boot入口类加上@EnableConfigurationProperties并指明要加载哪个bean,如果没有用此标签指定加载哪个class,在bean类那边添加@Configuration或者@Component ,

@Configuration为Spring中通过Java类配置bean的标签如下所示

  1. package com.my.sb.entity;
  2.  
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6.  
  7. @Configuration
  8. public class Data {
  9. @Value("${app.user.name}")
  10. private String name;
  11.  
  12. @Value("${app.user.age}")
  13. private int age;
  14.  
  15. @Value("${app.user.sex}")
  16. private String sex;
  17.  
  18. /**
  19. *
  20. */
  21. public Data() {
  22. super();
  23. }
  24.  
  25. /**
  26. * @return the name
  27. */
  28. public String getName() {
  29. return name;
  30. }
  31.  
  32. /**
  33. * @param name
  34. * the name to set
  35. */
  36. public void setName(String name) {
  37. this.name = name;
  38. }
  39.  
  40. /**
  41. * @return the age
  42. */
  43. public int getAge() {
  44. return age;
  45. }
  46.  
  47. /**
  48. * @param age
  49. * the age to set
  50. */
  51. public void setAge(int age) {
  52. this.age = age;
  53. }
  54.  
  55. /**
  56. * @return the sex
  57. */
  58. public String getSex() {
  59. return sex;
  60. }
  61.  
  62. /**
  63. * @param sex
  64. * the sex to set
  65. */
  66. public void setSex(String sex) {
  67. this.sex = sex;
  68. }
  69.  
  70. @Bean
  71. public Student getStudent() {
  72. Student stu = new Student();
  73.  
  74. stu.setName(name);
  75. stu.setSex(sex);
  76. stu.setAge(age);
  77.  
  78. return stu;
  79. }
  80.  
  81. }

@Component 为把当前类自动注入为bean,为通过注解配置bean,如下

  1. package com.my.sb.entity;
  2.  
  3. import org.springframework.boot.context.properties.ConfigurationProperties;
  4. import org.springframework.stereotype.Component;
  5.  
  6. @Component
  7. @ConfigurationProperties(prefix="app.user")
  8. public class ConfigData {
  9.  
  10. private String name;
  11.  
  12. private int age;
  13.  
  14. private String sex;
  15.  
  16. public String sexStr ="boy";
  17.  
  18. /**
  19. *
  20. */
  21. public ConfigData() {
  22. super();
  23. }
  24.  
  25. /**
  26. * @param name
  27. * @param age
  28. * @param sex
  29. */
  30. public ConfigData(String name, int age, String sex) {
  31. super();
  32. this.name = name;
  33. this.age = age;
  34. this.sex = sex;
  35. }
  36.  
  37. /**
  38. * @return the name
  39. */
  40. public String getName() {
  41. return name;
  42. }
  43.  
  44. /**
  45. * @param name the name to set
  46. */
  47. public void setName(String name) {
  48. this.name = name;
  49. }
  50.  
  51. /**
  52. * @return the age
  53. */
  54. public int getAge() {
  55. return age;
  56. }
  57.  
  58. /**
  59. * @param age the age to set
  60. */
  61. public void setAge(int age) {
  62. this.age = age;
  63. }
  64.  
  65. /**
  66. * @return the sex
  67. */
  68. public String getSex() {
  69. return sex;
  70. }
  71.  
  72. /**
  73. * @param sex the sex to set
  74. */
  75. public void setSex(String sex) {
  76. this.sex = sex;
  77. }
  78.  
  79. /* (non-Javadoc)
  80. * @see java.lang.Object#toString()
  81. */
  82. @Override
  83. public String toString() {
  84. return "User [name=" + name + ", age=" + age + ", sex=" + sex + "]";
  85. }
  86.  
  87. }

加载类

  1. package com.my.study;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.boot.context.properties.EnableConfigurationProperties;
  6.  
  7. import com.my.study.model.ConfigBean;
  8.  
  9. @SpringBootApplication
  10. @EnableConfigurationProperties(ConfigBean.class)
  11. public class Application {
  12.  
  13. public static void main(String[] args) {
  14. SpringApplication.run(Application.class, args);
  15. }
  16. }

最后在Controller中引入ConfigBean使用即可,如下:

  1. package com.my.study.controller;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RestController;
  7.  
  8. import com.my.study.model.ConfigBean;
  9.  
  10. @RestController
  11. @SpringBootApplication
  12. @RequestMapping("/user")
  13. public class UserController {
  14.  
  15. @Autowired
  16. ConfigBean configBean;
  17.  
  18. @RequestMapping("/test")
  19. public Object sayHello() {
  20.  
  21. return configBean;
  22. }
  23.  
  24. } 

三、参数间引用

在application.properties中的各个参数之间也可以直接引用来使用,就像下面的设置:

  1. test.stuName = Joe
  2. test.stuSex = gril
  3. test.allInfo = stuName:${test.stuName} stuSex:${test.stuSex}

 四、使用自定义新建的配置文件

注意:@PropertySource不支持yml文件读取。 

  1. package com.my.study.model;
  2.  
  3. import org.springframework.boot.context.properties.ConfigurationProperties;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.context.annotation.PropertySource;
  6.  
  7. @Configuration
  8. @ConfigurationProperties(prefix ="test")
  9. @PropertySource("classpath:config/my.properties")
  10.  
  11. public class Config {
  12.  
  13. private String stuName;
  14.  
  15. private String stuSex;
  16.  
  17. /* (non-Javadoc)
  18. * @see java.lang.Object#toString()
  19. */
  20. @Override
  21. public String toString() {
  22. return "ConfigBean [stuName=" + stuName + ", stuSex=" + stuSex + "]";
  23. }
  24.  
  25. /**
  26. * @return the stuName
  27. */
  28. public String getStuName() {
  29. return stuName;
  30. }
  31.  
  32. /**
  33. * @param stuName the stuName to set
  34. */
  35. public void setStuName(String stuName) {
  36. this.stuName = stuName;
  37. }
  38.  
  39. /**
  40. * @return the stuSex
  41. */
  42. public String getStuSex() {
  43. return stuSex;
  44. }
  45.  
  46. /**
  47. * @param stuSex the stuSex to set
  48. */
  49. public void setStuSex(String stuSex) {
  50. this.stuSex = stuSex;
  51. }
  52.  
  53. }

主要就是加了一个注解:@PropertySource("classpath:config/my.properties")

Spring Boot 通过@PropertySource或者@PropertySources实现设置多配置文件

注意:@PropertySource不支持yml文件读取。 

pring Boot 官网使用的是application.properties文件来实现文件的配置。但是实际情况下一个配置文件是不够用的,比如项目集成redis,mq,以及数据库比如mysql的时候,多个配置文件有利于开发及维护的管理。Spring Boot是通过@PropertySource或者@PropertySources来实现多配置文件的。首先看下@PropertySource源码:

  1. public @interface PropertySource {
  2.  
  3. /**
  4. * Indicate the name of this property source. If omitted, a name will
  5. * be generated based on the description of the underlying resource.
  6. * @see org.springframework.core.env.PropertySource#getName()
  7. * @see org.springframework.core.io.Resource#getDescription()
  8. */
  9. String name() default "";
  10.  
  11. /**
  12. * Indicate the resource location(s) of the properties file to be loaded.
  13. * <p>Both traditional and XML-based properties file formats are supported
  14. * &mdash; for example, {@code "classpath:/com/myco/app.properties"}
  15. * or {@code "file:/path/to/file.xml"}.
  16. * <p>Resource location wildcards (e.g. **/*.properties) are not permitted;
  17. * each location must evaluate to exactly one {@code .properties} resource.
  18. * <p>${...} placeholders will be resolved against any/all property sources already
  19. * registered with the {@code Environment}. See {@linkplain PropertySource above}
  20. * for examples.
  21. * <p>Each location will be added to the enclosing {@code Environment} as its own
  22. * property source, and in the order declared.
  23. */
  24. String[] value();
  25.  
  26. /**
  27. * Indicate if failure to find the a {@link #value() property resource} should be
  28. * ignored.
  29. * <p>{@code true} is appropriate if the properties file is completely optional.
  30. * Default is {@code false}.
  31. * @since 4.0
  32. */
  33. boolean ignoreResourceNotFound() default false;
  34.  
  35. /**
  36. * A specific character encoding for the given resources, e.g. "UTF-8".
  37. * @since 4.3
  38. */
  39. String encoding() default "";
  40.  
  41. /**
  42. * Specify a custom {@link PropertySourceFactory}, if any.
  43. * <p>By default, a default factory for standard resource files will be used.
  44. * @since 4.3
  45. * @see org.springframework.core.io.support.DefaultPropertySourceFactory
  46. * @see org.springframework.core.io.support.ResourcePropertySource
  47. */
  48. Class<? extends PropertySourceFactory> factory() default PropertySourceFactory.class;

name
为这里资源指定一个名称,这个没什么好说的。

value
用于指定资源路径,注意通配符(比如/*.properties)在这里是没有用的,路径必须明确指向到一个properties文件。因为这里value的类型是String数组,因此这里可以指定多个配置文件。

ignoreResourceNotFound
是否忽略找不到指定路径的情况。

encoding
指定编码类型,默认为空。

  1. @SpringBootApplication
  2. @ComponentScan(basePackages = {"com.aron"})//通过扫描本路径可不需将ctl包和启动类放在同一目录下
  3. @PropertySource(value= {"classpath:redis.properties","classpath:database.properties"}
  4. , name="ss"
  5. , encoding="utf-8"
  6. ,ignoreResourceNotFound=true)
  7. public class ProjectMainEntranceApplication {
  8.  
  9. public static void main(String[] args) {
  10. SpringApplication.run(ProjectMainEntranceApplication.class, args);
  11. }
  12. }

而对于@PropertySources 来说,参照其源码:

  1. public @interface PropertySources {
  2.  
  3. PropertySource[] value();
  4.  
  5. }

我们可以看到其实就是PropertySource的数组,因此通过@PropertySources 配置方式为:

  1. @SpringBootApplication
  2. @ComponentScan(basePackages = { "com.aron" }) // 通过扫描本路径可不需将ctl包和启动类放在同一目录下
  3. @PropertySources({ @PropertySource("classpath:redis.properties"),
  4. @PropertySource("classpath:database.properties") })
  5. public class ProjectMainEntranceApplication {
  6.  
  7. public static void main(String[] args) {
  8. SpringApplication.run(ProjectMainEntranceApplication.class, args);
  9. }
  10. }

通过@PropertySource源码解析我们就能够知道应该如何使用该注解。这里假设需要多配置两个配置文件:redis.properties和database.properties:

五、配置文件优先级

application.properties和application.yml文件可以放在一下四个位置:

  • 外置,在相对于应用程序运行目录的/congfig子目录里。(jar包同级目录下的/config目录)
  • 外置,在应用程序运行的目录里(jar包同级目录)
  • 内置,在config包内
  • 内置,在Classpath根目录

同样,这个列表按照优先级排序,也就是说,src/main/resources/config下application.properties覆盖src/main/resources下application.properties中相同的属性,

此外,如果你在相同优先级位置同时有application.properties和application.yml,那么application.yml里面的属性就会application.properties里的属性覆盖。

bootstrap.properties优先于application.prperties

properties优先于yml

resources/config优先于resources/

读取顺序

如果在不同的目录中存在多个配置文件,它的读取顺序是:

1、config/application.properties(项目根目录中config目录下)

2、config/application.yml

3、application.properties(项目根目录下)

4、application.yml

5、resources/config/application.properties(项目resources目录中config目录下)

6、resources/config/application.yml

7、resources/application.properties(项目的resources目录下)

8、resources/application.yml

注:

1、如果同一个目录下,有application.yml也有application.properties,默认先读取application.properties。

2、如果同一个配置属性,在多个配置文件都配置了,默认使用第1个读取到的,后面读取的不覆盖前面读取到的。(properties继承自Hashtable不保证读取顺序,yml可以按顺序读取)

3、创建SpringBoot项目时,一般的配置文件放置在“项目的resources目录下”

详见:https://www.cnblogs.com/lukelook/p/11245832.html

六.随机值配置

配置文件中${random} 可以用来生成各种不同类型的随机值,从而简化了代码生成的麻烦,例如 生成 int 值、long 值或者 string 字符串。

  1. dudu.secret=${random.value}
  2. dudu.number=${random.int}
  3. dudu.bignumber=${random.long}
  4. dudu.uuid=${random.uuid}
  5. dudu.number.less.than.ten=${random.int(10)}
  6. dudu.number.in.range=${random.int[1024,65536]}

七.外部配置-命令行参数配置

Spring Boot是基于jar包运行的,打成jar包的程序可以直接通过下面命令运行:

  1. java -jar xx.jar 

可以以下命令修改tomcat端口号:

  1. java -jar xx.jar --server.port=9090

可以看出,命令行中连续的两个减号--就是对application.properties中的属性值进行赋值的标识。
所以java -jar xx.jar --server.port=9090等价于在application.properties中添加属性server.port=9090
如果你怕命令行有风险,可以使用SpringApplication.setAddCommandLineProperties(false)禁用它。

实际上,Spring Boot应用程序有多种设置途径,Spring Boot能从多重属性源获得属性,包括如下几种:

  • 根目录下的开发工具全局设置属性(当开发工具激活时为~/.spring-boot-devtools.properties)。
  • 测试中的@TestPropertySource注解。
  • 测试中的@SpringBootTest#properties注解特性。
  • 命令行参数
  • SPRING_APPLICATION_JSON中的属性(环境变量或系统属性中的内联JSON嵌入)。
  • ServletConfig初始化参数。
  • ServletContext初始化参数。
  • java:comp/env里的JNDI属性
  • JVM系统属性
  • 操作系统环境变量
  • 随机生成的带random.* 前缀的属性(在设置其他属性时,可以应用他们,比如${random.long})
  • 应用程序以外的application.properties或者appliaction.yml文件
  • 打包在应用程序内的application.properties或者appliaction.yml文件
  • 通过@PropertySource标注的属性源
  • 默认属性(通过SpringApplication.setDefaultProperties指定).

这里列表按组优先级排序,也就是说,任何在高优先级属性源里设置的属性都会覆盖低优先级的相同属性,列如我们上面提到的命令行属性就覆盖了application.properties的属性。

通过命令行来修改属性值固然提供了不错的便利性,但是通过命令行就能更改应用运行的参数,那岂不是很不安全?是的,所以Spring Boot也贴心的提供了屏蔽命令行访问属性的设置,只需要这句设置就能屏蔽:SpringApplication.setAddCommandLineProperties(false)

详细参考:http://tengj.top/2017/02/28/springboot2/

八.springboot使用spring.profiles.active添加多个properties或者yml配置文件

原始配置文件application.properties内容如下:

  1. djg.name=DJG
  2. djg.age=22
  3. djg.desc=${lyw.name} is a boy
  4. #时间格式化
  5. spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

现在想要将配置文件的功能更加清晰化,thymeleaf模板引擎的配置要单独建一个配置文件,那么,可以作如下操作,在原始配置文件application.properties的首行加上”spring.profiles.active=thymeleaf”,变成如下:

  1. spring.profiles.active=thymeleaf#多个中间用逗号隔开
  2. djg.name=DJG
  3. djg.age=22
  4. djg.desc=${lyw.name} is a boy
  5. #时间格式化
  6. spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

然后,在原始配置文件同目录下另建一个名为application-thymeleaf.propertis的配置文件。

也可以用于不同生产环境的切换

@value也可以如下使用

  1. @RequestMapping(value = "/test", method = RequestMethod.GET)
  2. public ConfigData changeStr(@Value("${new.data}") String data) {
  3. System.out.println(data);
  4. return configData ;
  5.  
  6. }

new.data为在properties中配置的值

多环境配置

以上都不是重点,这才是重点,这才是重点,这才是重点,重要的事情说3遍。我们在开发Spring Boot应用时,通常同一套程序会被应用和安装到几个不同的环境,比如:开发、测试、生产等。其中每个环境的数据库地址、服务器端口等等配置都会不同,如果在为不同环境打包时都要频繁修改配置文件的话,那必将是个非常繁琐且容易发生错误的事。
    对于多环境的配置,各种项目构建工具或是框架的基本思路是一致的,通过配置多份不同环境的配置文件,再通过打包命令指定需要打包的内容之后进行区分打包,Spring Boot也不例外,或者说更加简单。
       在Spring Boot中多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,比如:
   application-dev.properties:开发环境
   application-test.properties:测试环境
   application-prod.properties:生产环境
       至于哪个具体的配置文件会被加载,需要在application.properties文件中通过spring.profiles.active属性来设置,其值对应{profile}值。
如:spring.profiles.active=test就会加载application-test.properties

spring.profiles.include的使用

application.properties

  1. #profiles
  2. spring.profiles.active=test

application-test.properties

  1. new.data=88test
  2. spring.profiles.include=testDb,testInfo

application-testDb.properties

  1. db=111

application-testInfo.properties

  1. info=This is a test!
  1. 总结:
  2. 多个配置文件中有同一个值,以下情况获取值的效果:
  3. 1.启动命令不带--spring.profiles.active参数以application.properties首先启动
  4. 按顺序所有文件第一个配置的spring.profiles.active属性中指定的最后一个文件中含有该属性的值为准
  5. 如果所有文件都没有spring.profiles.active,那么以pring.profiles.include配置的最后一个属性文件中的值为准
  6. 2.启动命令带--spring.profiles.active参数以参数指定的属性文件首先启动
  7. 此情况,已命令指定的配置文件中的值为准,其他文件中再配置spring.profiles.active也不会生效,如果不存在值,那么会以pring.profiles.include指定的最后一个文件中的值为准
  8.  
  9. 简要说
  10. 启动命令spring.profiles.active指定文件中的值 > 文件中spring.profiles.active指定的文件列表中最后一次出现的值 > 文件中spring.profiles.include指定的文件列表中最后一次出现的值
  11.  
  12. (注意:无论是否配置启动命令参数指定文件,最后都会加载application.properties,它里边配置的信息也很关键)

 九.springboot 加载自定义yml文件

1.  ConfigurationProperties注解的locations属性在1.5.X以后没有了,不能指定locations来加载yml文件

2. PropertySource注解不支持yml文件加载,详细见官方文档: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-yaml-shortcomings

3. Spring Framework有两个类加载YAML文件,YamlPropertiesFactoryBean和YamlMapFactoryBean

4. 可以通过PropertySourcePlaceholderConfigurer来加载yml文件,暴露yml文件到spring environment

  1. @Configuration
  2. @ConfigurationProperties(ignoreUnknownFields =true)
  3. @Component("testConfig ")
  4. public class testConfig {
  5. private Map<String,String> testKey = new HashMap<>();
  6.  
  7. public Map<String, String> gettestKey () {
  8. return testKey ;
  9. }
  10.  
  11. public void settestKey (Map<String, String> testKey ) {
  12. this.testKey = testKey ;
  13. }
  14.  
  15. @Bean
  16. public static PropertySourcesPlaceholderConfigurer properties() {
  17. PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
  18. YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
  19. yaml.setResources(new ClassPathResource("xx.yml"));//class引入
  20. configurer.setProperties(yaml.getObject());
  21. return configurer;
  22. }
  23. }

或者用第三方jar例如snakeyml解析,详见:

SpringBoot properties和yml的区别

Spring Boot 中配置文件application.properties使用的更多相关文章

  1. Spring Boot中配置文件application.properties使用

    一.配置文档配置项的调用 启动后在浏览器直接输入http://localhost:18080/user/test,就直接打印出配置文件中的配置内容. 二.绑定对象bean调用 有时候属性太多了,一个个 ...

  2. Spring Boot 的配置文件application.properties

    Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...

  3. 一:Spring Boot 的配置文件 application.properties

    Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...

  4. 是时候搞清楚 Spring Boot 的配置文件 application.properties 了!

    在 Spring Boot 中,配置文件有两种不同的格式,一个是 properties ,另一个是 yaml . 虽然 properties 文件比较常见,但是相对于 properties 而言,ya ...

  5. 第二篇:彻底搞清楚 Spring Boot 的配置文件 application.properties

    前言 在Spring Boot中,配置文件有两种不同的格式,一个是properties,另一个是yaml. 虽然properties文件比较常见,但是相对于properties而言,yaml更加简洁明 ...

  6. 如果你的application.properties中还存在明文密码----加密Spring Boot中的application.properties

    1 概述 什么?都2020年了还在Spring Boot的配置文件中写明文密码? 虽然是小项目,明文也没人看. 明文简单快捷方便啊!!! 你看直接用户名root密码123456多么简单!!! ... ...

  7. Spring boot 全局配置文件application.properties

    #更改Tomcat端口号 server.port=8090 #修改进入DispatcherServlet的规则为:*.htmlserver.servlet-path=*.html#这里要注意高版本的s ...

  8. 【spring boot】配置文件 application.properties 属性解析

    1.JPA  hibernate命名策略 完整命名策略 ,查看:http://www.cnblogs.com/sxdcgaq8080/p/7910474.html 2.hibernate的DDL执行策 ...

  9. springboot中配置文件application.properties的理解

    前言 Spring Boot使用"习惯优于配置"(项目中存在大量的配置,此外还内置了一个习惯性的配置,让你无需手动进行配置)的理念让你的项目快速运行起来.所以,我们要想把Sprin ...

随机推荐

  1. iOS-AFN Post JSON格式数据

    - (void)postRequest{ AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; // >>> ...

  2. 关于loading

    在开发中,不可避免的会需要loading的出现,来提高用户体验, 自己在查找中,总结了两条: 1.window.onload的时候显示loading,首先loading图片是一直存在的,window. ...

  3. 关于小窗滑动,父级body也跟随滑动的解决方案(2)

    当第一次写这个问题的时候,并不知道竟然还会写2,而且(1)也并没有解决问题. 也发现,这个问题,真实也困住了很多人,找到了张鑫旭(http://www.zhangxinxu.com/wordpress ...

  4. 爽爽的GSON解析

    Gson解析的各种详细用法我就不说了. 说说我在项目具体遇到的. 当前公司的JSON解析基本上通过阿里的fastjson,以及JSONObject,JSONArray来解析.那种让我无语的感觉不是言语 ...

  5. 大牛是怎么思考设计MySQL优化方案

    在进行MySQL的优化之前,必须要了解的就是MySQL的查询过程,很多查询优化工作实际上就是遵循一些原则,让MySQL的优化器能够按照预想的合理方式运行而已. 1.优化的哲学 注:优化有风险,涉足需谨 ...

  6. python虚拟环境 | virtualenv 的简单使用 (图文)

    一.创建virtualenv虚拟环境 mkvirtualenv -p 版本号 虚拟名 mkvirtualenv -p python3 env_1 python3:版本号 env_1: 虚拟环境名称 创 ...

  7. 获取C#中方法的执行时间及其代码注入

    在优化C#代码或对比某些API的效率时,通常需要测试某个方法的运行时间,可以通过DateTime来统计指定方法的执行时间,也可以使用命名空间System.Diagnostics中封装了高精度计时器Qu ...

  8. Spring Boot初识(4)- Spring Boot整合JWT

    一.本文介绍 上篇文章讲到Spring Boot整合Swagger的时候其实我就在思考关于接口安全的问题了,在这篇文章了我整合了JWT用来保证接口的安全性.我会先简单介绍一下JWT然后在上篇文章的基础 ...

  9. 深入学习使用ocr算法识别图片中文字的方法

    公司有个需求,简单点说需要从一张图片中识别出中文,通过python来实现,当然其他程序也行,只要能实现,而小编主要学习python,所以就提了python.一个小白在网上遨游了一天,终于找到一丝丝思绪 ...

  10. 看图说话,idea 远程调试 tomcat下项目

    tomcat中部署了项目,准备测试远程调试. 1.配置idea 2. 修改catalina.bat,并启动tomcat catalina.bat: ...rem 下面的参数就是从idea配置中复制过来 ...