Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkuifang committed Apr 1, 2018
1 parent f76e779 commit 199e076
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 34 deletions.
35 changes: 24 additions & 11 deletions src/main/java/com/example/demo/common/Test.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.demo.common;

import java.util.Map;
import java.util.Properties;

/**
* 测试类
*
Expand All @@ -10,19 +13,29 @@ public class Test {


public static void main(String[] args) {
StringBuilder sql = new StringBuilder("insert into dyf_waterpail_info (pail_no,storagetype) values ");

for (int i = 0; i < 200; i++) {
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(i + 1900001);
sb.append(",");
sb.append(10007);
sb.append("),");
sql.append(sb);
// StringBuilder sql = new StringBuilder("insert into dyf_waterpail_info (pail_no,storagetype) values ");
//
// for (int i = 0; i < 200; i++) {
// StringBuilder sb = new StringBuilder();
// sb.append("(");
// sb.append(i + 1900001);
// sb.append(",");
// sb.append(10007);
// sb.append("),");
// sql.append(sb);
// }
// System.out.println(sql);
// JVM系统属性值
Properties properties = System.getProperties();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
System.err.println(entry.getKey() + ":" + entry.getValue());
}
System.out.println(sql);

// OS系统属性
Map<String, String> getenv = System.getenv();
for (String key : getenv.keySet()) {
System.err.println(key + ":" + getenv.get(key));
}

}
}
22 changes: 7 additions & 15 deletions src/main/java/com/example/demo/config/MyDefinedConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
import org.springframework.context.annotation.PropertySource;

/**
* 自定义外置配置
* 自定义外置配置(第三方配置文件获取推荐使用@ConfigurationProperties)
* 使用方法:1.直接使用@Value注解
* 2.使用@Autowired注解注入配置类,再通过getXXX()方法获取,如:
* 该方式是类型安全的
*
* @author QuiFar
* @Autowired private myConfiguration myConfig;
* myConfig.getXXX();
* <p>
* 注意:YAML files cannot be loaded by using the @PropertySource annotation.
* So, in the case that you need to load values that way, you need to use a properties file.
* 需要注意的是,如果需要@PropertySource注解,那就必须使用properties文件,不能使用yml文件
*/
@Configuration
@ConfigurationProperties(prefix = "author")
@PropertySource(value = "classpath:config/my-defined.yml")
@PropertySource(value = "classpath:config/my-defined.properties", encoding = "GBK")
public class MyDefinedConfiguration {
private String name;

Expand All @@ -26,17 +31,4 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

private static class Other {
private int age;

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.example.demo.config.MyDefinedConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -30,17 +32,24 @@
*/
@Controller
public class LoginController {
@Autowired
private MyDefinedConfiguration myDefinedConfiguration;

@Autowired
private UserService UserService;

@Value("${author.other.age}")
private int age;

/**
* 获取登陆初始化页面
*
* @return
*/
@GetMapping("/login")
public String login() {
//System.err.println("author.name: " + myDefinedConfiguration.getName());
//System.err.println("author.other.age: " + age);
return "login";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ logging.level.com.example.demo.mapper=debug
#spring.devtools.restart.exclude=static/**,public/**
#禁止客户端的JS对Cookie做读写操作,以便防御XSS攻击
server.session.cookie.http-only=true


#通过连接测试保证服务器释放掉jdbc连接后重连,保证连接的有效性
#spring.datasource.tomcat.validation-interval=10000
spring.datasource.tomcat.validation-query=SELECT 1
Expand All @@ -46,7 +44,10 @@ spring.datasource.tomcat.remove-abandoned-timeout=180
spring.datasource.tomcat.num-tests-per-eviction-run=10
#连接超时
spring.datasource.tomcat.max-wait=30000

#配置actuator系统健康监控
management.security.enabled=false
management.port=8080
management.port=8080

#日志控制台默认输出level是 warn,error,info; debug和trace默认不输出
#trace跟踪日志非常多,可以非常详细的看到所有的日志信息
debug=true
File renamed without changes.
5 changes: 5 additions & 0 deletions src/main/resources/config/my-defined.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#把自定义的常量值外置配置,方便管理
author.name=你好
author.user-name=userName
author.other.age=10
4 changes: 0 additions & 4 deletions src/main/resources/config/my-defined.yml

This file was deleted.

0 comments on commit 199e076

Please sign in to comment.