Skip to content

Commit

Permalink
优化百度API中配置步骤
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoxiongdu committed Jul 26, 2021
1 parent c297429 commit 68503c6
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 661 deletions.
7 changes: 5 additions & 2 deletions blog.iml
Expand Up @@ -14,7 +14,9 @@
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="Hibernate" />
<datasource-mapping />
<datasource-mapping>
<factory-entry name="entityManagerFactory" />
</datasource-mapping>
<naming-strategy-map />
</configuration>
</facet>
Expand All @@ -33,6 +35,8 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:1.5.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:1.5.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.5.7.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.5.7.RELEASE" level="project" />
Expand Down Expand Up @@ -123,7 +127,6 @@
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.4.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.11.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.3.11.RELEASE" level="project" />
</component>
Expand Down
653 changes: 3 additions & 650 deletions log/blog.log

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -28,6 +28,12 @@

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/cn/shaoxiongdu/BlogApplication.java
Expand Up @@ -10,5 +10,14 @@ public class BlogApplication {

public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(BlogApplication.class, args);

System.out.println("IoC容器中所有的组件:");
int count = 0;
String[] beanDefinitionNames = run.getBeanDefinitionNames();
for (String beanDefinitionName : beanDefinitionNames) {
System.out.println("IoC容器中" + ++count + "的组件: " + beanDefinitionName + "如下:");
System.out.println(run.getBean(beanDefinitionName));
System.out.println("============================================");
}
}
}
9 changes: 5 additions & 4 deletions src/main/java/cn/shaoxiongdu/util/BaiduApi.java
Expand Up @@ -7,20 +7,20 @@
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
* 百度API接口
*/
@Component
@PropertySource("application-prod.yml")
public class BaiduApi {

@Value("${accessKey}")
@Value("${baiduApi.accessKey}")
private String accessKey;

@Value("${secretKey}")
@Value("${baiduApi.secretKey}")
private String secretKey;

@Override
Expand Down Expand Up @@ -74,7 +74,8 @@ public String getAddressByIp(String ip){
response = client.sendRequest(request);

} catch (Exception e) {
e.printStackTrace();

return "百度API异常,请检查配置文件";
}

// 返回结果格式为Json字符串
Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/application-prod.yml
Expand Up @@ -11,11 +11,10 @@ spring:
show-sql: false
logging:
level:
root: error
com.lrm: error
root: warn
file: log/blog.log

# 用于通过IP查找地址的百度API
baiduApi:
accessKey:
accessKey: DSXdsx05117218
secretKey: f3c38615a64c4a6cbdc48fe2717830bc
3 changes: 1 addition & 2 deletions target/classes/application-prod.yml
Expand Up @@ -11,8 +11,7 @@ spring:
show-sql: false
logging:
level:
root: error
com.lrm: error
root: warn
file: log/blog.log

# 用于通过IP查找地址的百度API
Expand Down
Binary file modified target/classes/cn/shaoxiongdu/BlogApplication.class
Binary file not shown.
Binary file modified target/classes/cn/shaoxiongdu/util/BaiduApi$Address.class
Binary file not shown.
Binary file modified target/classes/cn/shaoxiongdu/util/BaiduApi.class
Binary file not shown.

0 comments on commit 68503c6

Please sign in to comment.