Я использую следующий стежок веб-приложений, и когда я запускаю свой тест TestNG, и контейнер инициализируется, мой тестовый класс не может autowire ExampleRepository с приведенным ниже исключением , Любые идеи о том, как сопоставить такие отношения? Когда я запускаю веб-сервер причала с тем же веб-приложением, я не получаю никаких исключений для запуска, поэтому это может быть проблема с AbstractTransactionalTestNGSpringContextTests.Spring Data Repository JPA Entity Inheritance Issue: невозможно создать экземпляр абстрактного класса или интерфейса
Stack:
Spring - 3.2.2.RELEASE
Spring Data - 1.3.0.RELEASE
Hibernate - 3.6.10.Final
TestNG - 6.1.1
Исключение:
Cannot instantiate abstract class or interface: com.test.Example; nested exception is org.hibernate.InstantiationException
JPA Сущности:
@Entity
@Table(name = "EXAMPLE")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public abstract class Example {}
@Entity
@DiscriminatorValue("examplea")
public class ExampleA extends Example {}
@Entity
@DiscriminatorValue("exampleb")
public class ExampleB extends Example {}
Repository:
public interface ExampleRepository extends JpaRepository<Example, Long> {}
TestNG Класс:
public class ExampleTest extends AbstractTransactionalTestNGSpringContextTests{
@Autowired
private ExampleRepository exampleRepository;
}
Я бы использовал конкретные репозитории 'ExempleARepository' и' ExempleBRepository' –