Так создается источник данных.
Код: Выделить всё
@Configuration
@Import(RewardsConfig.class)
public class TestInfrastructureConfig {
/**
* Creates an in-memory "rewards" database populated
* with test data for fast testing
*/
@Bean
public DataSource dataSource() {
return (new EmbeddedDatabaseBuilder()) //
.addScript("classpath:rewards/testdb/schema.sql") //
.addScript("classpath:rewards/testdb/data.sql") //
.build();
}
}
Код: Выделить всё
class RewardNetworkTests {
private RewardNetwork rewardNetwork;
@BeforeEach
void setUp() throws Exception {
ApplicationContext cxt = SpringApplication.run(TestInfrastructureConfig.class);
this.rewardNetwork = cxt.getBean(RewardNetwork.class);
}
@Test
void testRewardForDining() {
fail("Not yet implemented");
}
}
Код: Выделить всё
Caused by: java.io.FileNotFoundException: class path resource [rewards/testdb/schema.sql] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:199) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:146) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.jdbc.datasource.init.ScriptUtils.readScript(ScriptUtils.java:328) ~[spring-jdbc-5.3.23.jar:5.3.23]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:236) ~[spring-jdbc-5.3.23.jar:5.3.23]
... 122 common frames omitted
Вот структура дерева файлов:
Код: Выделить всё
├───.mvn
│ └───wrapper
├───.settings
├───00-rewards-common
│ ├───.settings
│ ├───src
│ │ ├───main
│ │ │ ├───java
│ │ │ │ └───common
│ │ │ │ ├───datetime
│ │ │ │ ├───money
│ │ │ │ └───repository
│ │ │ └───resources
│ │ │ └───rewards
│ │ │ └───testdb
│ │ └───test
│ │ └───java
│ │ └───common
│ │ ├───datetime
│ │ └───money
│ └───target
│ ├───classes
│ │ └───common
│ │ ├───datetime
│ │ ├───money
│ │ └───repository
│ ├───generated-sources
│ │ └───annotations
│ ├───generated-test-sources
│ │ └───test-annotations
│ ├───maven-archiver
│ ├───maven-status
│ │ └───maven-compiler-plugin
│ │ ├───compile
│ │ │ └───default-compile
│ │ └───testCompile
│ │ └───default-testCompile
│ ├───surefire-reports
│ └───test-classes
│ └───common
│ ├───datetime
│ └───money
─12-javaconfig-dependency-injection
│ ├───.settings
│ ├───src
│ │ ├───main
│ │ │ └───java
│ │ │ ├───config
│ │ │ └───rewards
│ │ │ └───internal
│ │ │ ├───account
│ │ │ ├───restaurant
│ │ │ └───reward
│ │ └───test
│ │ ├───java
│ │ │ ├───config
│ │ │ └───rewards
│ │ │ └───internal
│ │ └───resources
│ └───target
│ ├───classes
│ │ ├───config
│ │ ├───META-INF
│ │ │ └───maven
│ │ │ └───io.spring.training.core-spring
│ │ │ └───12-javaconfig-dependency-injection
│ │ └───rewards
│ │ └───internal
│ │ ├───account
│ │ ├───restaurant
│ │ └───reward
│ ├───generated-sources
│ │ └───annotations
│ ├───generated-test-sources
│ │ └───test-annotations
│ ├───maven-archiver
│ ├───maven-status
│ │ └───maven-compiler-plugin
│ │ ├───compile
│ │ │ └───default-compile
│ │ └───testCompile
│ │ └───default-testCompile
│ ├───surefire-reports
│ └───test-classes
│ ├───config
│ └───rewards
│ └───internal
Подробнее здесь: https://stackoverflow.com/questions/793 ... nother-lab
Мобильная версия