我有一个简单的主应用程序:
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = "dreamteam.eho")
@Import({EhoConfig.class})
public class MainApp implements CommandLineRunner, ApplicationContextAware {
Run Code Online (Sandbox Code Playgroud)
配置:
@Configuration
@EnableConfigurationProperties({RootProperties.class})
public class EhoConfig {
}
Run Code Online (Sandbox Code Playgroud)
和属性:
@ConfigurationProperties("root")
public class RootProperties {
private String name;
Run Code Online (Sandbox Code Playgroud)
我尝试加载配置:
--spring.config.location=file:///E:/.../eho-bot/props/ --spring.profiles.active=eho
Run Code Online (Sandbox Code Playgroud)
路径是正确的.但是没有加载yml;
application-eho.yml文件:
logging:
file: D:/java/projects/telegram-bots/eho.log
level:
dreamteam.eho: INFO
org.springframework: DEBUG
root:
name: EHO-BOT
Run Code Online (Sandbox Code Playgroud)
应用程序使用args运行,但所有props都为null.记录属性不适用; SOUT:
--spring.config.location=file:///E:.../eho-bot/props/
--spring.profiles.active=eho
--spring.output.ansi.enabled=always
Run Code Online (Sandbox Code Playgroud) 我有maven项目.Maven构建完整的SUCCESS.但我不能做这个项目.
[信息]建立成功
项目包含一个模块.Idea无法看到依赖关系.
Error:(3, 38) java: D:\Dropbox\Programming\java\spring\springBook\src\main\java\ch14\validator\ContactTestValidator.java:3:
package org.springframework.stereotype does not exist
Run Code Online (Sandbox Code Playgroud)
POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springBook</groupId>
<artifactId>springBook</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Shared version number properties -->
<properties>
<org.springframework.version>3.2.3.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!--??? ????????? ????? ??????????-->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<!--Spring Data JPA ?????????? ??? - ??????? ? ??????????-->
<!--API ??? ?????? ? ??????-->
<!--ch14 validator-->
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<!--ch14 validator-->
<!--API ?????????? JSR-303-->
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version> …Run Code Online (Sandbox Code Playgroud) 需要通过带有弹簧轮廓的gradle进行测试.
gradle clean build
Run Code Online (Sandbox Code Playgroud)
我添加了任务:
task beforeTest() {
doLast {
System.setProperty("spring.profiles.active", "DEV")
}
}
test.dependsOn beforeTest
Run Code Online (Sandbox Code Playgroud)
我的测试定义是:
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("TestProfile")
public class SomeTest {
Run Code Online (Sandbox Code Playgroud)
但这种结构对我不起作用.
Gradle运行测试.
有一个 Eureka Server 应用程序:
@EnableEurekaServer
@SpringBootApplication
public class RegistrationModulesServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RegistrationModulesServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
使用 appplicaton.yml 配置(默认):
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
server:
port: 1111
Run Code Online (Sandbox Code Playgroud)
在第一次运行时 - 我看到了带有状态的仪表板。就像在文档中一样:

为什么?
日志中没有错误。
有一个带有配置的 Spring Boot 应用程序:
spring:
jpa:
show-sql: true
properties:
hibernate:
jdbc:
batch_size: 20
order_inserts: true
order_updates: true
generate_statistics: true
format_sql: true
dialect: org.hibernate.dialect.PostgreSQL10Dialect
default_schema: ${SCHEMA}
Run Code Online (Sandbox Code Playgroud)
我使用 JpaRepository.saveAll 方法将新数据插入数据库。但我认为批处理不起作用。
有日志:
Session Metrics {
1501300 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
13234500 nanoseconds spent preparing 1013 JDBC statements;
1636949500 nanoseconds spent executing 1013 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C …Run Code Online (Sandbox Code Playgroud) spring ×5
java ×4
gradle ×1
hibernate ×1
jpa ×1
maven ×1
maven-3 ×1
postgresql ×1
profiling ×1
spring-boot ×1