Skip to content

Fragment repository implementation should be imported even it's not in basePackages of @EnableJpaRepositories #3287

Closed as not planned
@quaff

Description

@quaff

Given:

package com.example.demo;

public interface CustomRepository<T> {
	
	void customSave(T entity);

}
package com.example.demo;

public class CustomRepositoryImpl<T> implements CustomRepository<T> {

	@Override
	public void customSave(T entity) {
		throw new UnsupportedOperationException("Not Implemented");
	}

}
package test;

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.demo.CustomRepository;

public interface TestEntityRepository extends JpaRepository<TestEntity, Long>, CustomRepository<TestEntity> {

}

Then:

com.example.demo.CustomRepositoryImpl should be registered as repository fragment implementation implicitly since com.example.demo.CustomRepository is declared as repository fragment.

Actual:

Here is a failed test

package test;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.ContextConfiguration;

@DataJpaTest
//@EnableJpaRepositories(basePackageClasses = { TestEntityRepository.class, CustomRepository.class }) // will works
@EnableJpaRepositories(basePackageClasses = { TestEntityRepository.class })
@EntityScan(basePackageClasses = TestEntity.class)
@ContextConfiguration(classes = TestEntityRepositoryTests.class)
public class TestEntityRepositoryTests {

	@Autowired
	private TestEntityRepository testEntityRepository;

	@Test
	void test() {
		assertThatThrownBy(() -> testEntityRepository.customSave(new TestEntity()))
				.isInstanceOf(UnsupportedOperationException.class).hasMessage("Not Implemented");
	}

}

Minimal reproducible project: repository-scan.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions