Envisager de définir un bean de type "package" dans votre configuration [Source Démarrage]

J'obtiens l'erreur suivante:

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

Description:

Parameter 0 of method setApplicant in webService.controller.RequestController required a bean of type 'com.service.applicant.Applicant' that could not be found.


Action:

Consider defining a bean of type 'com.service.applicant.Applicant' in your configuration.

Je n'ai jamais vu cette erreur avant mais c'est bizarre que l' @Autowire ne fonctionne pas. Voici la structure du projet:

Demandeur Interface

public interface Applicant {

    TApplicant findBySSN(String ssn) throws ServletException;

    void deleteByssn(String ssn) throws ServletException;

    void createApplicant(TApplicant tApplicant) throws ServletException;

    void updateApplicant(TApplicant tApplicant) throws ServletException;

    List<TApplicant> getAllApplicants() throws ServletException;
}

ApplicantImpl

@Service
@Transactional
public class ApplicantImpl implements Applicant {

private static Log log = LogFactory.getLog(ApplicantImpl.class);

    private TApplicantRepository applicantRepo;

@Override
    public List<TApplicant> getAllApplicants() throws ServletException {

        List<TApplicant> applicantList = applicantRepo.findAll();

        return applicantList;
    }
}

Maintenant je devrais être en mesure de simplement Autowire Candidat et être en mesure d'accéder, dans ce cas, toutefois, il ne fonctionne pas quand je l'appelle dans mon @RestController:

@RestController
public class RequestController extends LoggingAware {

    private Applicant applicant;

    @Autowired
    public void setApplicant(Applicant applicant){
        this.applicant = applicant;
    }

    @RequestMapping(value="/", method = RequestMethod.GET)
    public String helloWorld() {

        try {
            List<TApplicant> applicantList = applicant.getAllApplicants();

            for (TApplicant tApplicant : applicantList){
                System.out.println("Name: "+tApplicant.getIndivName()+" SSN "+tApplicant.getIndSsn());
            }

            return "home";
        }
        catch (ServletException e) {
            e.printStackTrace();
        }

        return "error";
    }

}

------------------------Mise à JOUR 1-----------------------

J'ai ajouté

@SpringBootApplication
@ComponentScan("module-service")
public class WebServiceApplication extends SpringBootServletInitializer {

    @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WebServiceApplication.class);
    }

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

}

et l'erreur est allé loin, mais rien ne s'est passé. Cependant quand j'ai commenté tout ce qui concerne le Applicant dans le RestController avant d'ajouter @ComponentScan() j'ai été en mesure de retourner une chaîne de la UI, ce qui veut dire que mon RestController travaillait, maintenant, elle est ignorée. Je laid Whitelabel Error Page maintenant.

---------------------Mise à JOUR 2------------------------------

J'ai ajouté le module de base de la fève, c'était de se plaindre. Erreur de lit:

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

Description:

Parameter 0 of method setApplicantRepo in com.service.applicant.ApplicantImpl required a bean of type 'com.delivery.service.request.repository.TApplicantRepository' that could not be found.


Action:

Consider defining a bean of type 'com.delivery.request.request.repository.TApplicantRepository' in your configuration.

J'ai ajouté @ComponentScan

@SpringBootApplication
@ComponentScan({"com.delivery.service","com.delivery.request"})
public class WebServiceApplication extends SpringBootServletInitializer {

    @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WebServiceApplication.class);
    }

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

}

----------------------------Mise à jour 3----------------------

ajoutant:

@SpringBootApplication
@ComponentScan("com")
public class WebServiceApplication extends SpringBootServletInitializer {

est toujours à se plaindre de mes ApplicantImpl classe qui @Autowires mon repo TApplicantRepository en elle.

  • Où en est votre demande de fichier de contexte? Si vous n'en avez pas, vous devriez envisager de donner le Printemps quelques allusions à des annotations comme @ComponentScan à faire tous les haricots disponibles.
  • consultez la mise à jour 1
  • Je suppose après chaque mise à jour il y a eu des changements dans les erreurs? Si possible, faire publier votre projet de la structure, et les journaux d'erreurs/stacktrace dans chaque cas.. c'est mieux de savoir "Pourquoi" de ces erreur s'est produite, plutôt que d'un "quelque chose" fait disparaître l'erreur. Sera utile pour d'autres personnes qui viennent à travers une semblable question.
InformationsquelleAutor Drew1208 | 2016-11-02