web-dev-qa-db-ja.com

ネストされた例外はJava.lang.IllegalArgumentException:マネージタイプではありません:クラス

ServiceJpaRepositoryを使用して、実行時にSpring-Boot applicationに接続しているJPAにアクセスするHibernateにアクセスするPostgreSQL DBをデプロイしようとしています。 src/main/resources/application.propertiesの接続プロパティ

ビルドされた.WARをTomcatにデプロイすると、以下のエラーログに示されているエラーでアプリケーションが起動しません。

誰かがこのエラーの意味を助けてくれますか?

MyServiceImplおよびMyRequestBodyクラスの問題点に注意しましたが、Springフレームワークを初めて使用するため、エラーの正確な理由はわかりません。

Spring Boot Starterプロジェクトの関連クラスの定義は次のとおりです。

スプリングブートアプリケーション

@SpringBootApplication
@ComponentScan(<root package name under which all subpackages containing relevant classes >)
public class MySpringBootApplication extends SpringBootServletInitializer {

私のSpring-Boot RestControllerクラス(MyServiceクラスインスタンスの自動配線)

@RestController
public class MyController {

    @Autowired
    MyService myService;

My Serviceインターフェース(@Serviceアノテーションを提供していません)

public interface MyService {
    //all service method definitions
}

PostgreSQL DBで動作する自動配線リポジトリインスタンスを持つSpring ServiceImplクラス

@Service("myService")
public class MyServiceImpl implements MyService {

       @Autowired
       private MyRepository myRepository; <-- **ERROR -- Bean not found** 

       //other default services e.g. find, add, delete, update, etc.

}

マイリポジトリクラス

@Repository
public interface MyRepository extends JpaRepository<MyRequestBody, Long> {
    @Query("select h from MyRequestBody h where h.column1 = ?1")
    List<MyRequestBody> findByColumn1(String col1);
}

エンティティクラス

@Entity
@Table(name = "myTable", schema = "my_db")
public class MyRequestBody { <-- **ERROR -- Not a managed class type**

     @Id
     @Column(name = "id")
     @GeneratedValue(strategy = GenerationType.SEQUENCE)
     private Long id;
     @Column(name = "column1")
     private String column1;

//getter and setter AND toString methods

エラーログ(Tomcatでの.WARのデプロイ時)

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-12-28 15:50:23.282 ERROR 5320 --- [ost-startStop-1] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyController': Unsatisfied dependency expressed through field 'myService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myService': Unsatisfied dependency expressed through field 'myRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepository': Invocation of init method failed; nested exception is Java.lang.IllegalArgumentException: Not a managed type: class com.rest.MyRequestBody

@EntityScan( "entities_package_name")を追加した後

***************************
APPLICATION FAILED TO START
***************************

Description:

Field myRepository in com.rest.MyServiceImpl required a bean of type 'com.rest.MyRepository' that could not be found.


Action:

Consider defining a bean of type 'com.rest.MyRepository' in your configuration.

29-Dec-2017 08:22:25.023 SEVERE [localhost-startStop-1] org.Apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
 org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/spring-boot-service]]
        at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:167)
        at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:752)
        at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:728)
        at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:734)
        at org.Apache.catalina.startup.HostConfig.deployWAR(HostConfig.Java:986)
        at org.Apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.Java:1857)
        at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:511)
        at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
        at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1149)
        at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:624)
        at Java.lang.Thread.run(Thread.Java:748)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myController': Unsatisfied dependency expressed through field 'myService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myService': Unsatisfied dependency expressed through field 'myRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.rest.MyRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:588)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:88)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:366)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1264)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:553)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:543)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.Java:303)
        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.Java:154)
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.Java:134)
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.Java:87)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.Java:169)
        at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5196)
        at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
        ... 10 more
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myService': Unsatisfied dependency expressed through field 'myRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.rest.MyRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:588)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:88)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:366)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1264)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:553)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:306)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:302)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:202)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.Java:208)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:1138)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:1066)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:585)
        ... 32 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.rest.MyRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.Java:1493)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:1104)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:1066)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:585)
        ... 45 more

29-Dec-2017 08:22:25.026 SEVERE [localhost-startStop-1] org.Apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/home/sunilg/Apache-Tomcat-8.5.24/webapps/spring-boot-service.war]
 Java.lang.IllegalStateException: ContainerBase.addChild: start: org.Apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/spring-boot-service]]
        at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:756)
        at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:728)
        at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:734)
        at org.Apache.catalina.startup.HostConfig.deployWAR(HostConfig.Java:986)
        at org.Apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.Java:1857)
        at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:511)
        at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
        at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1149)
        at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:624)
        at Java.lang.Thread.run(Thread.Java:748)
6

Springはあなたのエンティティを認識していません。 MySpringBootApplicationクラスを@EntityScan("your.entities.package")で示す必要があります

18