web-dev-qa-db-ja.com

java.lang.IllegalArgumentException:マネージ型ではありません

Spring bootおよびjpaを使用しています。 こちら

私はこのようなドメインを持っています。また、Entityアノテーションは非推奨のようですので、代わりにDynamicUpdateを使用しています。

@Data
@AllArgsConstructor
@NoArgsConstructor
@DynamicUpdate
public class Person {
    private String id;
    private String name;
}

私のSpringBootApplicationクラスは次のようになります

@SpringBootApplication
@ComponentScan("com.lapots.breed.platform.cloud.boot")
@EnableJpaRepositories("com.lapots.breed.platform.cloud.boot.repository")
@EntityScan("com.lapots.breed.platform.cloud.boot.domain")
public class JavaCloudSampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(JavaCloudSampleApplication.class, args);
    }

    // executed after all beans instantiated
    @Bean
    public CommandLineRunner data(PersonRepository repository) {
        return (args) -> {
            repository.save(new Person(UUID.randomUUID().toString(), "Nike"));
        };
    }
}

repositoryクラスは次のようになります

@Repository
public interface PersonRepository extends JpaRepository<Person, String> {
}

このクラスを使用するserviceは次のようになります

@Service
@Transactional
public class PersonService implements IPersonService {

    @Autowired
    private PersonRepository personRepository;

    @Override
    public Person findPerson(String id) {
        return personRepository.findOne(id);
    }

    @Override
    public Person generatePerson() {
        Person person = new Person();
        person.setId(UUID.randomUUID().toString());
        person.setName("Nike");
        return person;
    }
}

しかし、アプリケーションを起動するとエラーが発生します

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'personService': Unsatisfied dependency expressed through field 'personRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error
 creating bean with name 'personRepository': Invocation of init method failed; nested exception is Java.lang.IllegalArgumentException: Not a managed type: class com.lapots.breed.platform.cloud.boot.domain.Person
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:588) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:88) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:366) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1264) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:553) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:483) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:306) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:302) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:197) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:761) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:867) ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:543) ~[spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:122) ~[spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:693) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:360) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.Java:303) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1118) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1107) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at com.lapots.breed.platform.cloud.boot.app.JavaCloudSampleApplication.main(JavaCloudSampleApplication.Java:23) [classes!/:0.0.1-SNAPSHOT]
        at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
        at Sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]
        at Sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]
        at Java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_121]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:48) [Java-cloud-rest-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.Java:87) [Java-cloud-rest-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.Java:50) [Java-cloud-rest-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.Java:51) [Java-cloud-rest-api-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Invocation of init method failed; nested exception is Java.lang.IllegalArgumentException: Not a managed type: class com.lapots.breed.platform.cl
oud.boot.domain.Person
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1628) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:555) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:483) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:306) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:302) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:202) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.Java:208) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:1138) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:1066) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:585) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        ... 27 common frames omitted
Caused by: Java.lang.IllegalArgumentException: Not a managed type: class com.lapots.breed.platform.cloud.boot.domain.Person
        at org.hibernate.jpa.internal.metamodel.MetamodelImpl.managedType(MetamodelImpl.Java:210) ~[hibernate-entitymanager-5.0.12.Final.jar!/:5.0.12.Final]
        at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.Java:70) ~[spring-data-jpa-1.11.6.RELEASE.jar!/:na]
        at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.Java:68) ~[spring-data-jpa-1.11.6.RELEASE.jar!/:na]
        at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.Java:153) ~[spring-data-jpa-1.11.6.RELEASE.jar!/:na]
        at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.Java:100) ~[spring-data-jpa-1.11.6.RELEASE.jar!/:na]
        at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.Java:82) ~[spring-data-jpa-1.11.6.RELEASE.jar!/:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.Java:199) ~[spring-data-commons-1.13.6.RELEASE.jar!/:na]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.Java:277) ~[spring-data-commons-1.13.6.RELEASE.jar!/:na]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.Java:263) ~[spring-data-commons-1.13.6.RELEASE.jar!/:na]
        at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.Java:101) ~[spring-data-jpa-1.11.6.RELEASE.jar!/:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1687) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1624) ~[spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        ... 37 common frames omitted

何が問題ですか?

17
lapots

JPAを使用しているため、おそらくPersonにはEntity注釈が必要です。

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@DynamicUpdate
public class Person {
    private String id;
    private String name;
}
28
Indra Basak