2
votes

I Have this test:

    @RunWith(SpringRunner.class)
    @DataJpaTest(excludeFilters = @Filter(type = FilterType.REGEX,
                                    pattern = "io\\.rainrobot\\.adwisdom\\.repository\\.es\\..*"))
    public class AskTest {

that should not scan repositories in this packege: io.rainrobot.adwisdom.repository.ex.* - but when i run the test i get this error:

Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.domain.Page io.rainrobot.adwisdom.repository.es.AskElasticRepository.findByTitle(java.lang.String,org.springframework.data.domain.PageRequest)! No property title found for type Ask!

here are the configurations:

    @SpringBootApplication public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }}
    @Configuration
    @EnableTransactionManagement
    @EnableJpaRepositories(basePackages="io.rainrobot.adwisdom.repository.sql") 
    @EntityScan(basePackages = {"io.rainrobot.adwisdom.dto"},
                basePackageClasses = {Jsr310JpaConverters.class})
    public class  JpaConfig {
    }
    @Configuration
    @EnableElasticsearchRepositories(basePackages=
        "io.rainrobot.adwisdom.repository.es")
    @EntityScan(basePackages = {"io.rainrobot.adwisdom.dto"},
        basePackageClasses = {Jsr310JpaConverters.class})
    public class ElasticsearchCongifuration {
        @Value("${elasticsearch.host:localhost}")
        public String host;
        @Value("${elasticsearch.port:9300}")
        public int port;

        @Bean
        public Client client(){
            TransportClient client = null;
            try{
                InetAddress inetAddress = InetAddress.getByName(host);
                TransportAddress transportAddress
                    = new TransportAddress(inetAddress, port);
                client = new PreBuiltTransportClient(Settings.EMPTY)
                    .addTransportAddress(transportAddress);
             } catch (UnknownHostException e) {  }
             return client;
        }
    }

and the application.properties:

# JPA config
spring.datasource.url=jdbc:mysql://localhost:3306/advisdom?useTimezone=true&serverTimezone=UTC&createDatabaseIfNotExist=true
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

# Local Elasticsearch config
elasticsearch.host=localhost
elasticsearch.port=9200

loggin.level.org.springframework: DEBUG

# App config
server.port=8102
spring.application.name=BootElastic

how can i exclude components with @DataJpaTest ?

1

1 Answers

1
votes

The filter only affects the component scan. If that scan finds your configuration this line:

@EnableElasticsearchRepositories(basePackages=
    "io.rainrobot.adwisdom.repository.es")

Will then enable the repositories for the package you tried to exclude.

At least that is my understanding. It should be easy to verify if you remove that line from you configuration.