CSE
spring-interview-questions.pdf

Class unit tests runwith

Info icon This preview shows pages 23–39. Sign up to view the full content.

SpringContext.class);
Image of page 23

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

Unit Tests @RunWith (SpringJUnit4ClassRunner.class) @ContextConfiguration (classes = JavaTestContext.class) public class DependencyInjectionJavaContextExamples { @RunWith (SpringJUnit4ClassRunner.class) @ContextConfiguration (locations = { "/TestContext.xml" }) public class TodoBusinessTest {
Image of page 24
Questions How does Spring know where to search for Components or Beans? What is a component scan? How do you define a component scan in XML and Java Configurations? How is it done with Spring Boot?
Image of page 25

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

Java Configuration @Configuration @ComponentScan (basePackages = { "com.in28minutes.spring.example1.businessservice" , "com.in28minutes.spring.example1.dataservice.stub" }) class SpringContext { }
Image of page 26
XML Configuration <?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns = " " xmlns:aop = " " xmlns:context = " xmlns:xsi = " " xsi:schemaLocation = " <context:component-scan base-package = "com.in28minutes.example" /> </beans>
Image of page 27

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

Spring Boot package com.in28minutes.spring.basics.springin5steps; @SpringBootApplication public class SpringIn5StepsApplication { package com.in28minutes.spring.basics.springin5steps; @RunWith (SpringRunner.class) @SpringBootTest public class SpringIn5StepsApplicationTests {
Image of page 28
Questions What does @Component signify? What does @Autowired signify? What’s the difference Between @Controller, @Component, @Repository, and @Service Annotations in Spring?
Image of page 29

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

Notes @Component - Spring should manage the bean. @Autowired - Spring should find the matching bean and wire the dependency in.
Image of page 30
@Component public class ComplexAlgorithmImpl { @Autowired private SortAlgorithm sortAlgorithm; public interface SortAlgorithm { public int [] sort( int [] numbers); } @Component public class QuickSortAlgorithm implements SortAlgorithm {
Image of page 31

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

Notes @Component - Generic Component @Repository - encapsulating storage, retrieval, and search behavior typically from a relational database @Service - Business Service Facade @Controller - Controller in MVC pattern
Image of page 32
Image of page 33

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

Questions What is the default scope of a bean? Are Spring beans thread safe? What are the other scopes available? How is Spring’s singleton bean different from Gang of Four Singleton Pattern?
Image of page 34
Notes The singleton scope is the default scope in Spring. The Gang of Four defines Singleton as having one and only one instance per ClassLoader. However, Spring singleton is defined as one instance of bean definition per container.
Image of page 35

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

Other Scopes singleton - One instance per Spring Context prototype - New bean whenever requested request - One bean per HTTP request. Web-aware Spring ApplicationContext. session - One bean per HTTP session. Web-aware Spring ApplicationContext.
Image of page 36
Examples @RequestScope @Component public class RequestScopedBean { @SessionScope @Component public class SessionScopedBean { <bean id = "someBean" class = "com.in28minutes.SomeBean" scope = "prototype" />
Image of page 37

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

Questions What are the different types of dependency injections?
Image of page 38
Image of page 39
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '18
  • LN Rao
  • public class, Spring Framework, Spring Boot, Spring Security

{[ 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