ich versucht, einige Einheiten in der db shemaWarum @PostConstruct nicht im Frühjahr Container aufgerufen?
Config hinzuzufügen:
@Configuration
@ComponentScan(ApplicationConfig.basePackage)
public class ApplicationConfig {
public final static String basePackage = "test"
}
Federbehälter Aufruf:
public class StartApp {
public static void main(String... args) throws Exception{
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
TestEntityRepository repository = (TestEntityRepository) context.getBean("testEntityRepository");
repository.save(new TestEntity("test"));
}
}
Zielklasse mit Anmerkung:
public class PersistenceService {
@Autowired
TestEntityRepository testEntityRepository;
@PostConstruct
public void initialize(){
//repository.deleteAll();
testEntityRepository.save(new TestEntity("test1"));
testEntityRepository.save(new TestEntity("test2"));
testEntityRepository.save(new TestEntity("test3"));
}
}
als Ergebnis in Tabelle nur ein Datensatz - "Test". Am Tomcat funktioniert alles gut.
https://github.com/GlebSa/TestSpringJPA
Woher wissen Sie, dass die Datenbank nur einen Datensatz enthält, da Sie scheinbar eine eingebettete In-Memory-Datenbank verwenden? –