title: nested exception is java.lang.IllegalArgumentException: Not a managed type: class
body: <p>I am trying to deploy a <code>Spring-Boot application</code> with <code>Service</code> accessing a <code>JpaRepository</code> which is connecting to <code>PostgreSQL DB</code> at runtime using <code>JPA</code> and <code>Hibernate</code>, refering to connection properties in <code>src/main/resources/application.properties</code></p>
  
  <p>When I am deploying the built .WAR on Tomcat, the Application is failing to start with the error as given in below Error Log.</p>
  
  <p>Can somebody please help out what is the meaning of this error?</p>
  
  <p><strong>Note</strong> I have noted the trouble points in <code>MyServiceImpl</code> and <code>MyRequestBody</code> classes but I am not getting the exact reason for the error, as I am new to Spring framework.</p>
  
  <p>The definitions of the relevant classes in my Spring Boot Starter project are as follows:</p>
  
  <blockquote>
    <p>Spring Boot Application</p>
  </blockquote>
  
  <pre><code>@SpringBootApplication
  @ComponentScan(&lt;root package name under which all subpackages containing relevant classes &gt;)
  public class MySpringBootApplication extends SpringBootServletInitializer {
  </code></pre>
  
  <blockquote>
    <p>My Spring-Boot RestController class (autowiring the MyService class instance )</p>
  </blockquote>
  
  <pre><code>@RestController
  public class MyController {
  
      @Autowired
      MyService myService;
  </code></pre>
  
  <blockquote>
    <p>My Service interface (I have not provided any @Service annotation)</p>
  </blockquote>
  
  <pre><code>public interface MyService {
      //all service method definitions
  }
  </code></pre>
  
  <blockquote>
    <p>Spring ServiceImpl class with the autowiring repository instance to operate on PostgreSQL DB</p>
  </blockquote>
  
  <pre><code>@Service("myService")
  public class MyServiceImpl implements MyService {
  
         @Autowired
         private MyRepository myRepository; &lt;-- **ERROR -- Bean not found** 
  
         //other default services e.g. find, add, delete, update, etc.
  
  }
  </code></pre>
  
  <blockquote>
    <p>My Repository class</p>
  </blockquote>
  
  <pre><code>@Repository
  public interface MyRepository extends JpaRepository&lt;MyRequestBody, Long&gt; {
      @Query("select h from MyRequestBody h where h.column1 = ?1")
      List&lt;MyRequestBody&gt; findByColumn1(String col1);
  }
  </code></pre>
  
  <blockquote>
    <p>My Entity class</p>
  </blockquote>
  
  <pre><code>@Entity
  @Table(name = "myTable", schema = "my_db")
  public class MyRequestBody { &lt;-- **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
  </code></pre>
  
  <blockquote>
    <p>Error Log (on deploying .WAR on Tomcat)</p>
  </blockquote>
  
  <pre><code>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
  </code></pre>
  
  <blockquote>
    <p>After adding @EntityScan("entities_package_name")</p>
  </blockquote>
  
  <pre><code>***************************
  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)
  </code></pre>