Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 在Spring Boot中使用Junit测试Hibernet时出现问题_Hibernate_Spring Boot_Jpa_Junit - Fatal编程技术网

Hibernate 在Spring Boot中使用Junit测试Hibernet时出现问题

Hibernate 在Spring Boot中使用Junit测试Hibernet时出现问题,hibernate,spring-boot,jpa,junit,Hibernate,Spring Boot,Jpa,Junit,我想测试Spring数据层 我有基本的@Entity产品: @Entity @Table(name = "products") @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" }) public class Product{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "i_user") p

我想测试Spring数据层 我有基本的
@Entity
产品:

@Entity
@Table(name = "products")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Product{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "i_user")
    private int id;

    @Column(name = "user_name")
    private String userName;
我有
ProductRepository
Repository:

public interface ProductRepository extends JpaRepository<Product, Integer> {

}
我有一个错误:

18:53:15.926 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.ProductTest]
18:53:15.942 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
18:53:15.954 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
18:53:15.987 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.ProductTest] from class [org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper]
18:53:16.012 [main] INFO org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.ProductTest], using SpringBootContextLoader
18:53:16.020 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.ProductTest]: class path resource [com/ProductTest-context.xml] does not exist
18:53:16.021 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.ProductTest]: class path resource [com/ProductTestContext.groovy] does not exist
18:53:16.022 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.ProductTest]: no resource found for suffixes {-context.xml, Context.groovy}.
18:53:16.023 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.ProductTest]: ProductTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
18:53:16.134 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.ProductTest]

您使用的是哪个Spring启动版本?我使用的是这个版本
2.1.4.RELEASE
是否插入实体实例?是键入@Autowired private ProductRepository ProductRepository而不是private ProductRepository;。我在写文章时犯了错误。我正在使用
ProductRepository
。这不是问题。
18:53:15.926 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.ProductTest]
18:53:15.942 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
18:53:15.954 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
18:53:15.987 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.ProductTest] from class [org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper]
18:53:16.012 [main] INFO org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.ProductTest], using SpringBootContextLoader
18:53:16.020 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.ProductTest]: class path resource [com/ProductTest-context.xml] does not exist
18:53:16.021 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.ProductTest]: class path resource [com/ProductTestContext.groovy] does not exist
18:53:16.022 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.ProductTest]: no resource found for suffixes {-context.xml, Context.groovy}.
18:53:16.023 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.ProductTest]: ProductTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
18:53:16.134 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.ProductTest]