Spring数据jpa:findBy属性挂起在Junit测试中的"在阶段2147483647中启动bean"

Mar*_*ark 5 junit spring-data-jpa

我在访问spring数据jpa存储库时遇到了junit测试问题.我正在使用findByProperty功能.但它在访问时会挂起.

我的实体:

@Entity
@Table(name = "TC_ORDER")
public class Order extends AbstractCatalog{

        @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ORDER_SID")
    private Long id;

}
Run Code Online (Sandbox Code Playgroud)

我的抽象照片:

@MappedSuperclass
public abstract class AbstractCatalog {

   @Column(unique = true, nullable = false, name = "CODE",updatable=false)
    private String code;

    public void setCode(final String code) {
        this.code = code;
    }

public String getCode() {
        return this.code;
    }

}
Run Code Online (Sandbox Code Playgroud)

Spring数据jpa存储库:

public interface OrderRepository extends AbstractCatalogRepository<Order> {
}
Run Code Online (Sandbox Code Playgroud)

AbstractCatalogRepository:

@NoRepositoryBean
public interface AbstractCatalogRepository<T extends AbstractCatalog> extends
  CustomRepository<T, Serializable> {
     T findByCode(String code);
} 
Run Code Online (Sandbox Code Playgroud)

junit测试:

@Inject
    private OrderRepository orderRepository;

    @Test
    public void orderCatalogisComplete() throws Exception {
        Assert.assertNotNull(orderRepository); // OK
        Assert.assertEquals(18,orderRepository.count()); //OK       
    }
    @Test
    public void searchForSL1InDb(){

        Order sl1 = orderRepository.findByCode("SL-1"); // HANGS HERE
         Assert.assertNotNull(sl1);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是相关的结果日志记录:

...preceding spring integration logging (also used in my project)...
13:49:19.828 INFO  o.s.i.m.IntegrationMBeanExporter start 357 - started org.springframework.integration.monitor.IntegrationMBeanExporter@1202f4d
13:49:19.828 INFO  o.s.c.s.DefaultLifecycleProcessor start 334 - Starting beans in phase 2147483647
Run Code Online (Sandbox Code Playgroud)

它挂起..

She*_*hek 0

在 pom.xml 中添加以下给定的依赖项

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)