我用Intellij打开了restbucks项目.我安装了lombok插件,启用了注释处理.我在Intellij设置中使用javac编译器.我在项目根目录中有lombok.config,就像在git仓库中一样,我也尝试将它复制到src/main/java和src/main/resources但是无论我尝试什么,当我在发布订单后使用Intellij构建项目时,我明白了:
构造函数的参数#0 [org.springsource.restbucks.order.Order的构造函数,注释:{interface com.fasterxml.jackson.annotation.JsonCreator=@com.fasterxml.jackson.annotation.JsonCreator(mode = DEFAULT)}]没有属性名称注释; 当多参数构造函数注释为Creator时,必须具有名称
好像lombok.anyConstructor.suppressConstructorProperties=true没有效果.当我用maven构建时,它工作正常.当我删除lombok.config文件时,Intellij开始在整个项目中显示错误,因此该文件似乎被Intellij afterall识别.但是如上所述,对于订单的过帐失败,构建不会按预期运行.有谁知道这里发生了什么?
在spring boot 1.2.3.RELEASE with fasterxml什么是将LocalDate字段序列化和反序列化为iso日期格式化字符串的正确方法?
我试过了:
application.properties文件中的spring.jackson.serialization.write-dates-as-timestamps:false,
包括项目中的jackson-datatype-jsr310然后使用
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") 注解
和@DateTimeFormat(iso=ISO.DATE)注释,
将Jsr310DateTimeFormatAnnotationFormatterFactory添加为格式化程序:
@Override public void addFormatters(FormatterRegistry registry){registry.addFormatterForFieldAnnotation(new Jsr310DateTimeFormatAnnotationFormatterFactory()); }
以上都没有帮助.
我是 Spring Boot 的新手,制作了我的第一个实体。如何测试存储库?我正在使用本地 MySQL 数据库。那么第一步是模拟数据库吗?
@RunWith(SpringRunner.class)
@DataJpaTest
public class ClusterTest {
@Autowired
private TestEntityManager testEntityManager;
@Autowired
private ClusterRepository clusterRepository;
@Test
public void testExample() throws Exception{
this.testEntityManager.persist(new Cluster("Project", "System"));
Cluster cluster = this.clusterRepository.findOne(1);
assertThat(testcluster.getProject()).isEqualTo("System");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的集群实体
@Entity
@Table(name = "Cluster")
public class Cluster {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String project;
public Cluster(){
}
public Cluster(String project) {
this.project = project;
}
Run Code Online (Sandbox Code Playgroud)
我的存储库只是扩展了 JpaRepository。
我收到的错误是 java.lang.IllegalStateException: 无法加载 ApplicationContext。还有一点不足:无法用嵌入式数据库替换 DataSource 进行测试。如果您想要一个嵌入式数据库,请将受支持的数据库放在类路径上或调整@AutoconfigureTestDatabase 的替换属性。
这是我的 application.properties 文件,来自 src/main/resources/application.properties:
security.basic.enabled=false …Run Code Online (Sandbox Code Playgroud)