跳转至
本文阅读量

1. 6. ddd

1.1 6.11 如何自定以 JSON Serializers and Deserializers

1.1.1 编写自己的 JsonSerializer JsonDeserializer

1.1.2 通过 @JsonComponent

@JsonComponent
public class MyJsonComponent {

    public static class Serializer extends JsonSerializer<MyObject> {

        @Override
        public void serialize(MyObject value, JsonGenerator jgen, SerializerProvider serializers) throws IOException {
            jgen.writeStartObject();
            jgen.writeStringField("name", value.getName());
            jgen.writeNumberField("age", value.getAge());
            jgen.writeEndObject();
        }
    }

    public static class Deserializer extends JsonDeserializer<MyObject> {

        @Override
        public MyObject deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
            ObjectCodec codec = jsonParser.getCodec();
            JsonNode tree = codec.readTree(jsonParser);
            String name = tree.get("name").textValue();
            int age = tree.get("age").intValue();
            return new MyObject(name, age);
        }
    }
}

1.1 7. 异步任务执行和调度

2. 8. 测试(Testing)

几个核心概念

  • @SpringBootTest
  • @MockMvc
  • @MockBean

3. 9. 创建自己的自动配置(Auto-Configuration)

核心类或注解

  • @AutoConfiguration

  • @Conditional

    • @ConditionalOnClass
    • @ConditionalOnMissingClass

    • @ConditionalOnBean

    • @ConditionalOnMissingBean

    • @ConditionalOnProperty

    • @ConditionalOnResource

    • @ConditionalOnWebApplicatio

    • @ConditionalOnNotWebApplication
    • @ConditionalOnWarDeployment

    • @ConditionalOnExpression

  • @AutoConfigureBefore

  • @AutoConfigureAfter

3.1 9.5 创建自己的 starter

3.1.1 命名规则

  • 不要使用 spring-boot 作为开始
  • 使用如下形式 acme-spring-boot-starter

4. 10. Kotlin 的支持

5. 8. Developing Tools

5.1 Restart vs Reload

5.2 远程调试

首先在远程 SpringBoot 应用中不能排除(需要包含) devtool

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludeDevtools>false</excludeDevtools>
            </configuration>
        </plugin>
    </plugins>
</build>

5.1 HowTo

5.1.1 如何排除某项的自动配置

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class MyApplication {

}