Spring MVC Rest API - No qualifying bean of type 'com.app.dao.AdminsRepository'










0















This is my first experience using Spring MVC with REST API for having an angular front end. I created 3 configuration files:



Here is my ApplicationConfig



package com.app.config;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import javax.persistence.EntityManagerFactory;

@SuppressWarnings("unused")
@EnableWebMvc
@Configuration
@ComponentScan("com.app.controller")
@EnableJpaRepositories("com.app.dao")
public class ApplicationConfig
@Bean
public InternalResourceViewResolver setup()
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;


@Bean
public DataSource dataSource()
System.out.println("in datasoure");
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/db");
dataSource.setUsername("root");
dataSource.setPassword("");
return dataSource;


@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory()
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("com.app.model");
factory.setDataSource(dataSource());
return factory;


@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf)
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;




MVC Config



package com.app.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@EnableWebMvc
@Configuration
public class MvcConfig implements WebMvcConfigurer
public void configureViewResolvers(ViewResolverRegistry registry)
registry.jsp("/WEB-INF/views/", ".jsp");


@Bean
public InternalResourceViewResolver setup()
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;




WebInitializer



package com.app.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer

@Override
protected Class<?> getRootConfigClasses()
return null;

@Override
protected Class<?> getServletConfigClasses()
return new Class ApplicationConfig.class, MvcConfig.class ;

@Override
protected String getServletMappings()
return new String "/" ;




I also created a controller :



package com.app.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.app.dao.AdminsRepository;
import com.app.model.Admin;

@SuppressWarnings("unused")
@Controller
public class AdminsController

@Autowired
private AdminsRepository adminsRepository;

@GetMapping("/admins")
@ResponseBody
public String getAllAdmins(Model model)
return adminsRepository.findAll().toString();


@GetMapping("/admin/id")
@ResponseBody
public String getAdmin(@PathVariable("id") int id, Model model)
return adminsRepository.findById((long) id).orElse(null).toString();

@PostMapping("/admin")
@ResponseBody
public String createAdmin(Admin admin, Model model)
System.out.println(admin);
return adminsRepository.save(admin).toString();




The repository :



package com.app.dao;

//import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.app.model.Admin;

@Repository
public interface AdminsRepository extends JpaRepository <Admin, Long>


And my model :



package com.app.model;

import java.io.Serializable;
import javax.persistence.*;

import java.sql.Timestamp;
import java.util.List;

@Entity
@Table(name="admins")
@NamedQuery(name="Admin.findAll", query="SELECT a FROM Admin a")
public class Admin implements Serializable
private static final long serialVersionUID = 1L;

@Id
private int id;

@Column(name="created_at")
private Timestamp createdAt;

private String email;
private String login;
private String password;
private String name;
private String surname;
// ... getters and setters + delegated methods



When I start running the application and open the browser I receive an error message:



No qualifying bean of type 'com.app.dao.AdminsRepository' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
@org.springframework.beans.factory.annotation.Autowired(required=true)









share|improve this question




























    0















    This is my first experience using Spring MVC with REST API for having an angular front end. I created 3 configuration files:



    Here is my ApplicationConfig



    package com.app.config;

    import javax.persistence.EntityManagerFactory;
    import javax.sql.DataSource;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
    import org.springframework.jdbc.datasource.DriverManagerDataSource;
    import org.springframework.orm.jpa.JpaTransactionManager;
    import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
    import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
    import org.springframework.transaction.PlatformTransactionManager;
    import org.springframework.web.servlet.config.annotation.EnableWebMvc;
    import org.springframework.web.servlet.view.InternalResourceViewResolver;
    import javax.persistence.EntityManagerFactory;

    @SuppressWarnings("unused")
    @EnableWebMvc
    @Configuration
    @ComponentScan("com.app.controller")
    @EnableJpaRepositories("com.app.dao")
    public class ApplicationConfig
    @Bean
    public InternalResourceViewResolver setup()
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;


    @Bean
    public DataSource dataSource()
    System.out.println("in datasoure");
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/db");
    dataSource.setUsername("root");
    dataSource.setPassword("");
    return dataSource;


    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory()
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(true);
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan("com.app.model");
    factory.setDataSource(dataSource());
    return factory;


    @Bean
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf)
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(emf);
    return transactionManager;




    MVC Config



    package com.app.config;

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.EnableWebMvc;
    import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    import org.springframework.web.servlet.view.InternalResourceViewResolver;

    @EnableWebMvc
    @Configuration
    public class MvcConfig implements WebMvcConfigurer
    public void configureViewResolvers(ViewResolverRegistry registry)
    registry.jsp("/WEB-INF/views/", ".jsp");


    @Bean
    public InternalResourceViewResolver setup()
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;




    WebInitializer



    package com.app.config;

    import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

    public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer

    @Override
    protected Class<?> getRootConfigClasses()
    return null;

    @Override
    protected Class<?> getServletConfigClasses()
    return new Class ApplicationConfig.class, MvcConfig.class ;

    @Override
    protected String getServletMappings()
    return new String "/" ;




    I also created a controller :



    package com.app.controller;

    import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.ResponseBody;

    import com.app.dao.AdminsRepository;
    import com.app.model.Admin;

    @SuppressWarnings("unused")
    @Controller
    public class AdminsController

    @Autowired
    private AdminsRepository adminsRepository;

    @GetMapping("/admins")
    @ResponseBody
    public String getAllAdmins(Model model)
    return adminsRepository.findAll().toString();


    @GetMapping("/admin/id")
    @ResponseBody
    public String getAdmin(@PathVariable("id") int id, Model model)
    return adminsRepository.findById((long) id).orElse(null).toString();

    @PostMapping("/admin")
    @ResponseBody
    public String createAdmin(Admin admin, Model model)
    System.out.println(admin);
    return adminsRepository.save(admin).toString();




    The repository :



    package com.app.dao;

    //import java.util.List;
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;

    import com.app.model.Admin;

    @Repository
    public interface AdminsRepository extends JpaRepository <Admin, Long>


    And my model :



    package com.app.model;

    import java.io.Serializable;
    import javax.persistence.*;

    import java.sql.Timestamp;
    import java.util.List;

    @Entity
    @Table(name="admins")
    @NamedQuery(name="Admin.findAll", query="SELECT a FROM Admin a")
    public class Admin implements Serializable
    private static final long serialVersionUID = 1L;

    @Id
    private int id;

    @Column(name="created_at")
    private Timestamp createdAt;

    private String email;
    private String login;
    private String password;
    private String name;
    private String surname;
    // ... getters and setters + delegated methods



    When I start running the application and open the browser I receive an error message:



    No qualifying bean of type 'com.app.dao.AdminsRepository' available:
    expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
    @org.springframework.beans.factory.annotation.Autowired(required=true)









    share|improve this question


























      0












      0








      0


      1






      This is my first experience using Spring MVC with REST API for having an angular front end. I created 3 configuration files:



      Here is my ApplicationConfig



      package com.app.config;

      import javax.persistence.EntityManagerFactory;
      import javax.sql.DataSource;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.ComponentScan;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
      import org.springframework.jdbc.datasource.DriverManagerDataSource;
      import org.springframework.orm.jpa.JpaTransactionManager;
      import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
      import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
      import org.springframework.transaction.PlatformTransactionManager;
      import org.springframework.web.servlet.config.annotation.EnableWebMvc;
      import org.springframework.web.servlet.view.InternalResourceViewResolver;
      import javax.persistence.EntityManagerFactory;

      @SuppressWarnings("unused")
      @EnableWebMvc
      @Configuration
      @ComponentScan("com.app.controller")
      @EnableJpaRepositories("com.app.dao")
      public class ApplicationConfig
      @Bean
      public InternalResourceViewResolver setup()
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("/WEB-INF/views/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;


      @Bean
      public DataSource dataSource()
      System.out.println("in datasoure");
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName("com.mysql.jdbc.Driver");
      dataSource.setUrl("jdbc:mysql://localhost:3306/db");
      dataSource.setUsername("root");
      dataSource.setPassword("");
      return dataSource;


      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory()
      HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      vendorAdapter.setGenerateDdl(true);
      LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
      factory.setJpaVendorAdapter(vendorAdapter);
      factory.setPackagesToScan("com.app.model");
      factory.setDataSource(dataSource());
      return factory;


      @Bean
      public PlatformTransactionManager transactionManager(EntityManagerFactory emf)
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(emf);
      return transactionManager;




      MVC Config



      package com.app.config;

      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.web.servlet.config.annotation.EnableWebMvc;
      import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
      import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
      import org.springframework.web.servlet.view.InternalResourceViewResolver;

      @EnableWebMvc
      @Configuration
      public class MvcConfig implements WebMvcConfigurer
      public void configureViewResolvers(ViewResolverRegistry registry)
      registry.jsp("/WEB-INF/views/", ".jsp");


      @Bean
      public InternalResourceViewResolver setup()
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("/WEB-INF/views/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;




      WebInitializer



      package com.app.config;

      import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

      public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer

      @Override
      protected Class<?> getRootConfigClasses()
      return null;

      @Override
      protected Class<?> getServletConfigClasses()
      return new Class ApplicationConfig.class, MvcConfig.class ;

      @Override
      protected String getServletMappings()
      return new String "/" ;




      I also created a controller :



      package com.app.controller;

      import java.util.List;

      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.GetMapping;
      import org.springframework.web.bind.annotation.PathVariable;
      import org.springframework.web.bind.annotation.PostMapping;
      import org.springframework.web.bind.annotation.ResponseBody;

      import com.app.dao.AdminsRepository;
      import com.app.model.Admin;

      @SuppressWarnings("unused")
      @Controller
      public class AdminsController

      @Autowired
      private AdminsRepository adminsRepository;

      @GetMapping("/admins")
      @ResponseBody
      public String getAllAdmins(Model model)
      return adminsRepository.findAll().toString();


      @GetMapping("/admin/id")
      @ResponseBody
      public String getAdmin(@PathVariable("id") int id, Model model)
      return adminsRepository.findById((long) id).orElse(null).toString();

      @PostMapping("/admin")
      @ResponseBody
      public String createAdmin(Admin admin, Model model)
      System.out.println(admin);
      return adminsRepository.save(admin).toString();




      The repository :



      package com.app.dao;

      //import java.util.List;
      import org.springframework.data.jpa.repository.JpaRepository;
      import org.springframework.stereotype.Repository;

      import com.app.model.Admin;

      @Repository
      public interface AdminsRepository extends JpaRepository <Admin, Long>


      And my model :



      package com.app.model;

      import java.io.Serializable;
      import javax.persistence.*;

      import java.sql.Timestamp;
      import java.util.List;

      @Entity
      @Table(name="admins")
      @NamedQuery(name="Admin.findAll", query="SELECT a FROM Admin a")
      public class Admin implements Serializable
      private static final long serialVersionUID = 1L;

      @Id
      private int id;

      @Column(name="created_at")
      private Timestamp createdAt;

      private String email;
      private String login;
      private String password;
      private String name;
      private String surname;
      // ... getters and setters + delegated methods



      When I start running the application and open the browser I receive an error message:



      No qualifying bean of type 'com.app.dao.AdminsRepository' available:
      expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
      @org.springframework.beans.factory.annotation.Autowired(required=true)









      share|improve this question
















      This is my first experience using Spring MVC with REST API for having an angular front end. I created 3 configuration files:



      Here is my ApplicationConfig



      package com.app.config;

      import javax.persistence.EntityManagerFactory;
      import javax.sql.DataSource;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.ComponentScan;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
      import org.springframework.jdbc.datasource.DriverManagerDataSource;
      import org.springframework.orm.jpa.JpaTransactionManager;
      import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
      import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
      import org.springframework.transaction.PlatformTransactionManager;
      import org.springframework.web.servlet.config.annotation.EnableWebMvc;
      import org.springframework.web.servlet.view.InternalResourceViewResolver;
      import javax.persistence.EntityManagerFactory;

      @SuppressWarnings("unused")
      @EnableWebMvc
      @Configuration
      @ComponentScan("com.app.controller")
      @EnableJpaRepositories("com.app.dao")
      public class ApplicationConfig
      @Bean
      public InternalResourceViewResolver setup()
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("/WEB-INF/views/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;


      @Bean
      public DataSource dataSource()
      System.out.println("in datasoure");
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName("com.mysql.jdbc.Driver");
      dataSource.setUrl("jdbc:mysql://localhost:3306/db");
      dataSource.setUsername("root");
      dataSource.setPassword("");
      return dataSource;


      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory()
      HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      vendorAdapter.setGenerateDdl(true);
      LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
      factory.setJpaVendorAdapter(vendorAdapter);
      factory.setPackagesToScan("com.app.model");
      factory.setDataSource(dataSource());
      return factory;


      @Bean
      public PlatformTransactionManager transactionManager(EntityManagerFactory emf)
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(emf);
      return transactionManager;




      MVC Config



      package com.app.config;

      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.web.servlet.config.annotation.EnableWebMvc;
      import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
      import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
      import org.springframework.web.servlet.view.InternalResourceViewResolver;

      @EnableWebMvc
      @Configuration
      public class MvcConfig implements WebMvcConfigurer
      public void configureViewResolvers(ViewResolverRegistry registry)
      registry.jsp("/WEB-INF/views/", ".jsp");


      @Bean
      public InternalResourceViewResolver setup()
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("/WEB-INF/views/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;




      WebInitializer



      package com.app.config;

      import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

      public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer

      @Override
      protected Class<?> getRootConfigClasses()
      return null;

      @Override
      protected Class<?> getServletConfigClasses()
      return new Class ApplicationConfig.class, MvcConfig.class ;

      @Override
      protected String getServletMappings()
      return new String "/" ;




      I also created a controller :



      package com.app.controller;

      import java.util.List;

      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.web.bind.annotation.GetMapping;
      import org.springframework.web.bind.annotation.PathVariable;
      import org.springframework.web.bind.annotation.PostMapping;
      import org.springframework.web.bind.annotation.ResponseBody;

      import com.app.dao.AdminsRepository;
      import com.app.model.Admin;

      @SuppressWarnings("unused")
      @Controller
      public class AdminsController

      @Autowired
      private AdminsRepository adminsRepository;

      @GetMapping("/admins")
      @ResponseBody
      public String getAllAdmins(Model model)
      return adminsRepository.findAll().toString();


      @GetMapping("/admin/id")
      @ResponseBody
      public String getAdmin(@PathVariable("id") int id, Model model)
      return adminsRepository.findById((long) id).orElse(null).toString();

      @PostMapping("/admin")
      @ResponseBody
      public String createAdmin(Admin admin, Model model)
      System.out.println(admin);
      return adminsRepository.save(admin).toString();




      The repository :



      package com.app.dao;

      //import java.util.List;
      import org.springframework.data.jpa.repository.JpaRepository;
      import org.springframework.stereotype.Repository;

      import com.app.model.Admin;

      @Repository
      public interface AdminsRepository extends JpaRepository <Admin, Long>


      And my model :



      package com.app.model;

      import java.io.Serializable;
      import javax.persistence.*;

      import java.sql.Timestamp;
      import java.util.List;

      @Entity
      @Table(name="admins")
      @NamedQuery(name="Admin.findAll", query="SELECT a FROM Admin a")
      public class Admin implements Serializable
      private static final long serialVersionUID = 1L;

      @Id
      private int id;

      @Column(name="created_at")
      private Timestamp createdAt;

      private String email;
      private String login;
      private String password;
      private String name;
      private String surname;
      // ... getters and setters + delegated methods



      When I start running the application and open the browser I receive an error message:



      No qualifying bean of type 'com.app.dao.AdminsRepository' available:
      expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
      @org.springframework.beans.factory.annotation.Autowired(required=true)






      spring rest spring-mvc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 2:12









      Mozahler

      2,16151826




      2,16151826










      asked Nov 14 '18 at 19:57









      davidveradavidvera

      71116




      71116






















          2 Answers
          2






          active

          oldest

          votes


















          1














          G'day David,



          Just breaking down the answer moiljter already gave you.



          You can only @Autowire objects that are declared in packages being scanned for components.



          Currently, your @ComponentScan annotation only includes your controller package:



          @ComponentScan("com.app.controller")


          Broaden the search slightly like so:



          @ComponentScan("com.app")


          Then it should pick up your AdminsRepository and hum nicely.



          Cheers,



          ALS






          share|improve this answer























          • It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

            – davidvera
            Nov 15 '18 at 9:14



















          0














          You need to add "com.app.dao" to the list of packages that Spring will scan for components (and maybe also "com.app.model" if any of those annotations are Spring ones), or just change it to scan "com.app" (which will include everything in your app.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307888%2fspring-mvc-rest-api-no-qualifying-bean-of-type-com-app-dao-adminsrepository%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            G'day David,



            Just breaking down the answer moiljter already gave you.



            You can only @Autowire objects that are declared in packages being scanned for components.



            Currently, your @ComponentScan annotation only includes your controller package:



            @ComponentScan("com.app.controller")


            Broaden the search slightly like so:



            @ComponentScan("com.app")


            Then it should pick up your AdminsRepository and hum nicely.



            Cheers,



            ALS






            share|improve this answer























            • It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

              – davidvera
              Nov 15 '18 at 9:14
















            1














            G'day David,



            Just breaking down the answer moiljter already gave you.



            You can only @Autowire objects that are declared in packages being scanned for components.



            Currently, your @ComponentScan annotation only includes your controller package:



            @ComponentScan("com.app.controller")


            Broaden the search slightly like so:



            @ComponentScan("com.app")


            Then it should pick up your AdminsRepository and hum nicely.



            Cheers,



            ALS






            share|improve this answer























            • It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

              – davidvera
              Nov 15 '18 at 9:14














            1












            1








            1







            G'day David,



            Just breaking down the answer moiljter already gave you.



            You can only @Autowire objects that are declared in packages being scanned for components.



            Currently, your @ComponentScan annotation only includes your controller package:



            @ComponentScan("com.app.controller")


            Broaden the search slightly like so:



            @ComponentScan("com.app")


            Then it should pick up your AdminsRepository and hum nicely.



            Cheers,



            ALS






            share|improve this answer













            G'day David,



            Just breaking down the answer moiljter already gave you.



            You can only @Autowire objects that are declared in packages being scanned for components.



            Currently, your @ComponentScan annotation only includes your controller package:



            @ComponentScan("com.app.controller")


            Broaden the search slightly like so:



            @ComponentScan("com.app")


            Then it should pick up your AdminsRepository and hum nicely.



            Cheers,



            ALS







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 '18 at 5:24









            ALovedSonALovedSon

            283




            283












            • It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

              – davidvera
              Nov 15 '18 at 9:14


















            • It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

              – davidvera
              Nov 15 '18 at 9:14

















            It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

            – davidvera
            Nov 15 '18 at 9:14






            It works much more better ... I also solved my second issue ... It was returning memory allocation I just forgot this : @GetMapping(path="/xxx", produces= "application/json") in my controller. Thanks

            – davidvera
            Nov 15 '18 at 9:14














            0














            You need to add "com.app.dao" to the list of packages that Spring will scan for components (and maybe also "com.app.model" if any of those annotations are Spring ones), or just change it to scan "com.app" (which will include everything in your app.






            share|improve this answer



























              0














              You need to add "com.app.dao" to the list of packages that Spring will scan for components (and maybe also "com.app.model" if any of those annotations are Spring ones), or just change it to scan "com.app" (which will include everything in your app.






              share|improve this answer

























                0












                0








                0







                You need to add "com.app.dao" to the list of packages that Spring will scan for components (and maybe also "com.app.model" if any of those annotations are Spring ones), or just change it to scan "com.app" (which will include everything in your app.






                share|improve this answer













                You need to add "com.app.dao" to the list of packages that Spring will scan for components (and maybe also "com.app.model" if any of those annotations are Spring ones), or just change it to scan "com.app" (which will include everything in your app.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 2:20









                moilejtermoilejter

                63947




                63947



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307888%2fspring-mvc-rest-api-no-qualifying-bean-of-type-com-app-dao-adminsrepository%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3

                    Museum of Modern and Contemporary Art of Trento and Rovereto