BAEL-2350 - DataJpaTest Configuration not found (#7996)
* BAEL-2350 - DataJpaTest Configuration not found Add a simple example to show how the correct (package) structure is for using @DataJpaTest * Removed link as requested
This commit is contained in:
committed by
maibin
parent
9fe4a4d6dd
commit
2f9e9d90c7
2
pom.xml
2
pom.xml
@@ -594,6 +594,7 @@
|
||||
|
||||
<module>tensorflow-java</module>
|
||||
<module>spf4j</module>
|
||||
<module>spring-boot-configuration</module>
|
||||
<module>spring-boot-flowable</module>
|
||||
<module>spring-boot-mvc-2</module>
|
||||
<module>spring-boot-performance</module>
|
||||
@@ -681,6 +682,7 @@
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-boot-camel</module>
|
||||
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-configuration</module>
|
||||
<module>spring-boot-client</module>
|
||||
|
||||
<module>spring-boot-crud</module>
|
||||
|
||||
5
spring-boot-configuration/README.md
Normal file
5
spring-boot-configuration/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Spring Boot Configuration
|
||||
|
||||
This module contains articles about Spring Boot Configuration.
|
||||
|
||||
### Relevant Articles:
|
||||
12
spring-boot-configuration/data-jpa-application/pom.xml
Normal file
12
spring-boot-configuration/data-jpa-application/pom.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<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>
|
||||
<artifactId>data-jpa-application</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-configuration</groupId>
|
||||
<artifactId>spring-boot-configuration</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.data.jpa;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ApplicationFound {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.data.jpa.application;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ApplicationNotFound {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.data.jpa;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJpaTest
|
||||
public class DataJpaUnitTest {
|
||||
|
||||
@Autowired
|
||||
private TestEntityManager entityManager;
|
||||
|
||||
@Test
|
||||
public void givenACorrectSetup_thenAnEntityManagerWillBeAvailable() {
|
||||
assertNotNull(entityManager);
|
||||
}
|
||||
}
|
||||
12
spring-boot-configuration/data-jpa-library/pom.xml
Normal file
12
spring-boot-configuration/data-jpa-library/pom.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<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>
|
||||
<artifactId>data-jpa-library</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-configuration</groupId>
|
||||
<artifactId>spring-boot-configuration</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.data.jpa.libarary.model;
|
||||
|
||||
public class Example {
|
||||
private String example;
|
||||
|
||||
public String getExample() {
|
||||
return example;
|
||||
}
|
||||
|
||||
public void setExample(String example) {
|
||||
this.example = example;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.data.jpa;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TestApplication {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.data.jpa.libarary;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJpaTest
|
||||
public class DataJpaUnitTest {
|
||||
|
||||
@Autowired
|
||||
private TestEntityManager entityManager;
|
||||
|
||||
@Test
|
||||
public void givenACorrectSetup_thenAnEntityManagerWillBeAvailable() {
|
||||
assertNotNull(entityManager);
|
||||
}
|
||||
|
||||
}
|
||||
61
spring-boot-configuration/pom.xml
Normal file
61
spring-boot-configuration/pom.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<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>com.baeldung.spring-boot-configuration</groupId>
|
||||
<artifactId>spring-boot-configuration</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>data-jpa-library</module>
|
||||
<module>data-jpa-application</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,4 +0,0 @@
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Rendering Exceptions in JSON with Spring](https://www.baeldung.com/spring-exceptions-json)
|
||||
Reference in New Issue
Block a user