I have this config in my app (EngineConfig.java):
@Component
@EnableAutoConfiguration
@EnableCaching
@EnableScheduling
@ComponentScan(basePackages = "com.exaple.package")
public class EngineConfig {
}
In package I have package components, which contains some beans mark annotation @Component:
So, I have some test:
@ContextConfiguration(classes = [
EngineConfig::class
])
@RunWith(SpringRunner::class)
class EngineTest {
@Test
fun factorial() {
//some test
}
}
The problem is that some beans from the components folder require a Datasource, but in this test I do not need to work with the database, so the Datasource is not created. Is it possible to specify in the test that Spring does not create some beans for which the autowired candidate is not found? Because of this, I get an error like this:
Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]
But in this test I don't need to work with the base, so I would like to exclude the creation of some beans.

Aucun commentaire:
Enregistrer un commentaire