Giter Site home page Giter Site logo

spring5-di-demo's Introduction

This repository is for an example application built in my Spring Framework 5 - Beginner to Guru

You can learn about my Spring Framework 5 Online course here.

spring5-di-demo's People

Contributors

springframeworkguru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spring5-di-demo's Issues

Profile not working with Two Primary

Hi John,
I was implementing the Spring Profile demo, but after annotating PrimaryGreetingService and PrimarySpanishGreetingService classes with @Profile and @primary and activating one of them in application.properties, found that it is not working as expected and giving exception as following

2020-04-08 12:35:06.777  INFO 9432 --- [           main] sam.springframework.DiDemoApplication    : Starting DiDemoApplication on Lenovo-PC with PID 9432 (C:\Users\Lenovo\Spring Project John Thompson\di-demo\target\classes started by Lenovo in C:\Users\Lenovo\Spring Project John Thompson\di-demo)
2020-04-08 12:35:06.779  INFO 9432 --- [           main] sam.springframework.DiDemoApplication    : The following profiles are active: = es
2020-04-08 12:35:07.180  WARN 9432 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myController' defined in file [C:\Users\Lenovo\Spring Project John Thompson\di-demo\target\classes\sam\springframework\controllers\MyController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'sam.springframework.services.GreetingService' available: expected single matching bean but found 3: constructorGreetingService,greetingServiceImpl,setterGreetingService
2020-04-08 12:35:07.187  INFO 9432 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-08 12:35:07.191 ERROR 9432 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Parameter 0 of constructor in sam.springframework.controllers.MyController required a single bean, but 3 were found:
	- constructorGreetingService: defined in file [C:\Users\Lenovo\Spring Project John Thompson\di-demo\target\classes\sam\springframework\services\ConstructorGreetingService.class]
	- greetingServiceImpl: defined in file [C:\Users\Lenovo\Spring Project John Thompson\di-demo\target\classes\sam\springframework\services\GreetingServiceImpl.class]
	- setterGreetingService: defined in file [C:\Users\Lenovo\Spring Project John Thompson\di-demo\target\classes\sam\springframework\services\SetterGreetingService.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

The code I have used is from intro_to_profiles branch and I am using Spring Boot 2.2.6. What could be the reason if all steps are followed correctly ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.