By name component public class autowired private

Info icon This preview shows pages 52–66. Sign up to view the full content.

View Full Document Right Arrow Icon
by Name @Component public class ComplexAlgorithmImpl { @Autowired private SortAlgorithm quickSortAlgorithm; public interface SortAlgorithm { public int [] sort( int [] numbers); } @Component public class QuickSortAlgorithm implements SortAlgorithm { @Component public class BubbleSortAlgorithm implements SortAlgorithm {
Image of page 52

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Questions How do you debug problems with Spring Framework? NoUniqueBeanDefinitionException NoSuchBeanDefinitionException What is @Primary? What is @Qualifier?
Image of page 53
No matching Components @Component public class ComplexAlgorithmImpl { @Autowired private SortAlgorithm sortAlgorithm; public interface SortAlgorithm { public int [] sort( int [] numbers); } public class QuickSortAlgorithm implements SortAlgorithm { public class BubbleSortAlgorithm implements SortAlgorithm {
Image of page 54

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
UnsatisfiedDependencyException: Error creating bean with name 'binarySearchImpl' : Unsatisfied dependency expressed through field 'sortAlgorithm' nested exception is org.springframework.beans. factory .: No qualifying bean of type 'com.in28minutes.spring.basics.springin5steps.SortAlgorithm' available: expected at least 1 bean which qualifies as autowire candidate Dependency annotations: { @org .springframework.beans. factory .annotation.Autowired (required= true )}
Image of page 55
Typically problems @Component missing or @ComponentScan not defined properly
Image of page 56

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Exception - Two matching Components @Component public class ComplexAlgorithmImpl { @Autowired private SortAlgorithm sortAlgorithm; public interface SortAlgorithm { public int [] sort( int [] numbers); } @Component public class QuickSortAlgorithm implements SortAlgorithm { @Component public class BubbleSortAlgorithm implements SortAlgorithm {
Image of page 57
Field sortAlgorithm in springin5steps.BinarySearchImpl required a single bean, but 2 were found: bubbleSortAlgorithm: defined in file [BubbleSortAlgorithm.class] quickSortAlgorithm: defined in file [QuickSortAlgorithm.class]
Image of page 58

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Primary @Component @Primary public class BubbleSortAlgorithm implements SortAlgorithm {
Image of page 59
Qualifier @Component public class ComplexAlgorithmImpl { @Autowired @Qualifier ( "mainAlgorithm" ) private SortAlgorithm sortAlgorithm; @Component @Qualifier ( "mainAlgorithm" ) public class BubbleSortAlgorithm implements SortAlgorithm {
Image of page 60

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Questions What is CDI (Contexts and Dependency Injection)? Does Spring Support CDI? Would you recommed to use CDI or Spring Annotations?
Image of page 61
CDI Java EE Dependency Injection Standard (JSR-330) Spring Supports most annotations @Inject (@Autowired) @Named (@Component & @Qualifier) @Singleton (Defines a scope of Singleton)
Image of page 62

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Questions What are the major features in different versions of Spring? What are new features in Spring Framework 4.0? What are new features in Spring Framework 5.0?
Image of page 63
Notes Spring 2.5 made annotation-driven configuration possible. Spring 3.0 made great use of the Java 5 improvements in language.
Image of page 64

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Spring 4.0 First version to fully support Java 8 features.
Image of page 65
Image of page 66
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern