Why should you use Spring Boot? www.edureka.co
Why should you use Spring Boot? Stability Based on JVM Open Source Cloud- Native Connectivity Flexibility www.edureka.co
Java Spring Boot Developer Salary Trend www.edureka.co
www.edureka.co
Spring Boot Interview Questions Whatarethedifferencesbetween SpringandSpringBoot? Question 1 www.edureka.co
Question 1 Whatarethedifferencesbetween SpringandSpringBoot? Spring SpringBoot AwebapplicationframeworkbasedonJava AmoduleofSpring Providestoolsandlibrariestocreate customizedwebapplications UsedtocreateaSpringapplicationproject whichcanjustrun/execute SpringismorecomplexthanSpringBoot SpringBootislesscomplexthantheSpring framework Takesanunopinionatedview Takesanopinionatedviewofaplatform Spring Boot Interview Questions www.edureka.co
WhatisSpringBootandmention theneedforit? Question 2 Spring Boot Interview Questions www.edureka.co
Question 2 Usedtocreate stand-alone Spring-based applications whichyoucanjustrun Spring Boot isaSpringmodulewhichaimstosimplifytheuseofthe SpringframeworkforJava development. Spring Boot Interview Questions www.edureka.co ❑ Auto-dependencyResolution ❑ EmbeddedHTTPservers ❑ Auto-configuration ❑ Managementendpoints ❑ SpringBootCLI WhatisSpringBootandmention theneedforit? AimsatRapid Application Development SpringBootframeworkcomeswith
WhataretheadvantagesofSpring Boot? Question 3 Spring Boot Interview Questions www.edureka.co
Question 3 Spring Boot Interview Questions www.edureka.co WhataretheadvantagesofSpring Boot? Advantages of Spring Boot 01 Provides autoconfiguration to load a set of default configuration for a quick start of the application 02Creates stand-alone applications with a range of non-functional features that are common to large classes of project 03 Spring Boot comes with embedded tomcat, servlet containers jetty to avoid the usage of WAR files 04Spring Boot provides an opinionated view to reduce the developer effort and simplify maven configurations
Question 3 Spring Boot Interview Questions www.edureka.co WhataretheadvantagesofSpring Boot? Advantages of Spring Boot 05 Provides CLI tool to develop and test applications 06Comes with Spring Boot starters to ensure dependency management and also provides various security metrics 07 Consists of a wide range of APIs for monitoring and managing applications in dev and prod. 08Integrates with Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security easily by avoiding boilerplate code.
MentionafewfeaturesofSpring Boot Question 4 Spring Boot Interview Questions www.edureka.co
Question 4 Spring Boot Interview Questions www.edureka.co MentionafewfeaturesofSpring Boot Spring CLISpring CLISpring CLI SpringBootCLIallowsyou toGroovyforwritingSpringboot applicationandavoids boilerplatecode. Starter DependencyStarter DependencyStarter Dependency Withthehelpofthisfeature, SpringBootaggregatescommon dependenciestogetherand eventuallyimprovesproductivity Spring InitializerSpring InitializerSpring Initializer Thisisbasicallyaweb application,whichcan createan internalprojectstructureforyou. Auto-configurationAuto-configurationAuto-configuration Theauto-configurationfeatureof SpringBoothelpsinloadingthe defaultconfigurationsaccordingto theprojectyouareworkingon Spring ActuatorSpring ActuatorSpring Actuator Thisfeatureprovideshelpwhile runningSpringBootapplications. Logging and SecurityLogging and SecurityLogging and Security ThisfeatureofSpringBoot,ensures thatalltheapplicationsmadeusing SpringBootareproperlysecured withoutanyhassle.
ExplainhowtocreateSpringBoot applicationusingMaven Question 5 Spring Boot Interview Questions www.edureka.co
Question 5 Spring Boot Interview Questions www.edureka.co ExplainhowtocreateSpringBoot applicationusingMaven TherearevariousapproachestocreateaSpringBootapplication using maven: ❑Spring Boot CLI ❑Spring Boot Project Wizard ❑Spring Boot Initializer ❑Spring Maven Project
Whatarethethepossiblesources ofexternalconfiguration? Question 6 Spring Boot Interview Questions www.edureka.co
Question 6 Spring Boot Interview Questions www.edureka.co Whatarethethepossiblesources ofexternalconfiguration? Application Properties Command Line Properties Profile Specific Properties MostPossibleSourcesOfExternalConfiguration
Canyouexplainwhathappensin thebackgroundwhenaSpringBoot Applicationis“RunasJava Application”? Question 7 Spring Boot Interview Questions www.edureka.co
Question 7 Spring Boot Interview Questions www.edureka.co Canyouexplainwhathappensin thebackgroundwhenaSpringBoot Applicationis“RunasJava Application”? WhenaSpring Boot application isexecutedas“Run as Java application”,thenitautomatically launches up the tomcat serverassoonasitsees,that youaredevelopingawebapplication.
WhataretheSpringBootstarters andwhatareavailablethe starters? Question 8 Spring Boot Interview Questions www.edureka.co
Question 8 WhataretheSpringBootstarters andwhatareavailablethe starters? Spring Boot Interview Questions www.edureka.co Spring Boot starters areasetofconvenient dependency managementproviderswhichcanbeusedintheapplicationtoenable dependencies. Thesestartersmakedevelopmenteasyandrapid.Allthe availablestarterscomeunderthe org.springframework.boot group.
Question 8 WhataretheSpringBootstarters andwhatareavailablethe starters? Spring Boot Interview Questions www.edureka.co 01 spring-boot-starter 02 spring-boot-starter-jdbc 03 spring-boot-starter-web 04 spring-boot-starter-data-jpa 05 spring-boot-starter-security 06 spring-boot-starter-aop 07 spring-boot-starter-test
Question 9 Spring Boot Interview Questions www.edureka.co ExplainSpringActuatorandits advantages
Question 9 ExplainSpringActuatorandits advantages Spring Boot Interview Questions www.edureka.co Spring Actuator isacoolfeatureofSpring Boot withthe helpofwhichyoucanseewhatishappeninginsidearunning application. TheSpringActuatorprovidesaveryeasywaytoaccesstheproduction- readyREST points andfetchallkindsofinformationfromtheweb. ThesepointsaresecuredusingSpring Security’s content negotiation strategy.
Question 10 Spring Boot Interview Questions www.edureka.co WhatisSpringBootdependency management?
Question 10 Spring Boot Interview Questions www.edureka.co WhatisSpringBootdependency management? Spring Boot dependency management isusedtomanage dependenciesandconfigurationautomaticallywithoutyouspecifyingthe versionforanyofthatdependencies.
Question 11 Spring Boot Interview Questions www.edureka.co Mentiontheminimum requirementsforaSpringboot System
Question 11 Spring Boot Interview Questions www.edureka.co Mentiontheminimum requirementsforaSpringboot System Spring Boot 2.1.7.Release requires ✓ Java8+ ✓ SpringFramework5.1.9+ Explicit Build Support ✓ Maven3.3+ ✓ Gradle4.4+ Servlet Container Support ✓ Tomcat9.0–ServletVersion4.0 ✓ Jetty9.4– ServletVersion3.1 ✓ Undertow2.0–Servlet Version4.0
Question 12 Spring Boot Interview Questions www.edureka.co Whatisthymeleafandhowtouse thymeleaf?
Question 12 Spring Boot Interview Questions www.edureka.co Thymeleaf is a server-side Java template engine used forwebapplications. Itaims to bringnaturaltemplatefor yourwebapplication andcan integrate well with Spring Framework and HTML5 Java web applications. Whatisthymeleafandhowtouse thymeleaf? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- thymeleaf</artifactId> </dependency>
Question 13 Spring Boot Interview Questions www.edureka.co Canwechangetheportof embeddedTomcatserverinSpring Boot?
Question 13 Spring Boot Interview Questions www.edureka.co Canwechangetheportof embeddedTomcatserverinSpring Boot? Yes,wecanchangetheportoftheembeddedtomcatserverbyusing theapplication properties file. Inthisfile,youhavetoaddapropertyof“server.port”andassignitto anyportyouwishto. Forexample,ifyouwanttoassignitto8081,thenyouhavetomention server.port=8081 Onceyoumentiontheportnumber,theapplicationpropertiesfilewill beautomaticallyloadedbySpringBootandtherequired configurationswillbeappliedontotheapplication.
Question 14 Spring Boot Interview Questions www.edureka.co WhatistheneedforSpringBoot DevTools?
Question 14 Spring Boot Interview Questions www.edureka.co Spring Boot Dev Tools isanelaboratedsetoftools andaimstomaketheprocessofdevelopinganapplicationeasier. Iftheapplicationrunsintheproduction,thenthismoduleis automaticallydisabled,repackagingofarchivesarealso excludedbydefault. So,theSpring Boot Developer Tools applies propertiestotherespectivedevelopmentenvironments. WhatistheneedforSpringBoot DevTools?
Question 14 Spring Boot Interview Questions www.edureka.co WhatistheneedforSpringBoot DevTools?
Question 14 Spring Boot Interview Questions www.edureka.co Spring Boot Dev Tools isanelaboratedsetoftoolsandaims tomaketheprocessofdevelopinganapplicationeasier. Iftheapplicationrunsintheproduction,thenthismoduleisautomatically disabled,repackagingofarchivesarealsoexcludedbydefault. WhatistheneedforSpringBoot DevTools? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- thymeleaf</artifactId> </dependency>
Question 15 Spring Boot Interview Questions www.edureka.co Mentionthestepstocreatea SpringBootprojectusing Spring Initializer
Question 15 Spring Boot Interview Questions www.edureka.co Spring Initializer isawebtoolprovidedbySpring.Withthe helpofthistool,youcancreateSpringBootprojectsbyjust providingprojectdetails. Mentionthestepstocreatea SpringBootprojectusing Spring Initializer
Question 15 Spring Boot Interview Questions www.edureka.co Mentionthestepstocreatea SpringBootprojectusing Spring Initializer ✓ Choose the maven project and the required dependencies. Then, fill the other required details like Group, Artifact, and then click on GenerateProject. ✓ Once the project is downloaded, extract the project on to your system ✓ Next, you have to import this project using the import option on the SpringToolSuiteIDE
Question 16 Spring Boot Interview Questions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC
Question 16 Spring Boot Interview Questions www.edureka.co SpringBootstarterprojectsprovidetherequiredlibrariesto connecttheapplicationwithJDBC. So,forexample,ifyoujusthavetocreateanapplication and connectitwithMYSQLdatabase,youcanfollowthebelowsteps: Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 1: Create a database in MySQL CREATE DATABASE example; Step 2: Create a table inside this database CREATE TABLE customers(customerid INT PRIMARY KEY NOT NULL AUTO_INCREMENT, customername VARCHAR(255));
Question 16 Spring Boot Interview Questions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 3: Create a Spring Boot project and provide the required details Step 4: Add JDBC, MySQL and web dependencies. spring.datasource.url=jdbc:mysql://localhost:3306/e xample spring.datasource.username=root spring.datasource.password=mysql spring.jpa.hibernate.ddl-auto=create-drop Step 5: Once the project is created, you have to configure the database into application properties.
Question 16 Spring Boot Interview Questions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 6: The main application.java class should have the following code: package com.edureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootAp plication; @SpringBootApplication public class SampleApplication { public static void main(String[] args) { SpringApplication.run(SampleApplication.class, args); } }
Question 16 Spring Boot Interview Questions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 7: You have to create a controller to handle the HTTP requests, by mentioning the following code: package com.edureka; Import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.RestController; @RestController public class JdbcController { @Autowired JdbcTemplate jdbc; @RequestMapping("/insert") public String index(){ jdbc.execute("insert into customers(name)values('Aryya')"); return "Data Entry Successful"; } }
Question 16 Spring Boot Interview Questions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 8: Finally execute this project as a Java application. Step 9: Open the URL (localhost:8080/insert), and you will see the output as data entry successful. You can also go forward and check if the data is entered into the table.
Question 17 Spring Boot Interview Questions www.edureka.co HowtoenableHTTP/2supportin SpringBoot
Question 17 Spring Boot Interview Questions www.edureka.co HowtoenableHTTP/2supportin SpringBoot YoucanenabletheHTTP/2supportinSpringBootby: server.http2.enabled=true
Question 18 Spring Boot Interview Questions www.edureka.co Whatarethe @RequestMapping and @RestControllerannotationin SpringBootusedfor?
Question 18 Spring Boot Interview Questions www.edureka.co Whatarethe @RequestMapping and @RestControllerannotationin SpringBootusedfor? ✓ Thisannotationisusedtoprovidetheroutinginformationandtellsto SpringthatanyHTTPrequestmustbemappedtotherespective method. ✓ Tousethisannotation,youhavetoimport org.springframework.web.bind.annotation.RequestMapping; @RequestMapping@RequestMapping ✓ Thisannotationisusedtoprovidetheroutinginformationandtellsto SpringthatanyHTTPrequestmustbemappedtotherespective method. ✓ Tousethisannotation, youhavetoimport org.springframework.web.bind.annotation.RequestMapping; @RestController@RestController
Question 18 Spring Boot Interview Questions www.edureka.co Whatarethe @RequestMapping and @RestControllerannotationin SpringBootusedfor? package com.edureka; import org.springframework.web.bind.annotation.RequestMapp ing; import org.springframework.web.bind.annotation.RestControl ler; @RestController public class SampleController { @RequestMapping("/example") public String example(){ return"Welcome To Edureka"; } } Consideryouhaveamethodexample()whichshouldmapwith/exampleURL.
Question 19 Spring Boot Interview Questions www.edureka.co WhatisSpringBootCLIandhowto executetheSpringBootproject usingbootCLI?
Question 19 Spring Boot Interview Questions www.edureka.co SpringBootCLIisatoolsupportedbytheofficial SpringFramework.The stepstoexecuteaSpringBootprojectareasfollows: ➢ DownloadtheCLItoolfromtheofficialsiteandextractthezipfile.The binfolderpresentintheSpringsetupisusedtoexecutetheSpring Bootapplication. ➢ SinceSpringBootCLIexecutesgroovyfiles,youneedtocreatea groovyfileforSpringBootapplication.So,todothat,openterminaland changethecurrentdirectorytobinfolder. WhatisSpringBootCLIandhowto executetheSpringBootproject usingbootCLI?
Question 19 Spring Boot Interview Questions www.edureka.co Createacontrollerasfollows: WhatisSpringBootCLIandhowto executetheSpringBootproject usingbootCLI? @RestController public class Sample { @RequestMapping("/example") String index(){ <h1>"Welcome To Edureka"</h1>; } } Executethegroovyfilebymentioning ./spring run Sample.groovy;
Question 20 Spring Boot Interview Questions www.edureka.co Whatarethedifferencesbetween JPAandHibernate?
Question 20 Spring Boot Interview Questions www.edureka.co Whatarethedifferencesbetween JPAandHibernate? JPAisaDataAccessAbstractionusedtoreducetheamountofboilerplate code JPAJPA HibernateisanimplementationofJavaPersistenceAPIandoffers benefitsofloosecoupling HibernateHibernate V/S
Howcanwecreateacustom endpointinSpringBootActuator? Question 21 Spring Boot Interview Questions www.edureka.co
Question 21 Spring Boot Interview Questions www.edureka.co TocreateacustomendpointinSpringBoot2.x,youcanusethe @Endpoint annotation. SpringBootalsoexposesendpointsusing@WebEndpointor, @WebEndpointExtensionoverHTTPwiththehelp ofSpringMVC,Jerseyetc. Howcanwecreateacustom endpointinSpringBootActuator?
WhatdoyouunderstandbySpring Data? Question 22 Spring Boot Interview Questions www.edureka.co
Question 22 Spring Boot Interview Questions www.edureka.co Spring Data aimstomakeiteasyforthedeveloperstouse relationalandnon-relationaldatabases,cloud-baseddataservices, andotherdataaccesstechnologies. So,basically,itmakesiteasyfordataaccessandstillretainsthe underlyingdata. WhatdoyouunderstandbySpring Data?
Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration Question 23 Spring Boot Interview Questions www.edureka.co
Question 23 Spring Boot Interview Questions www.edureka.co Auto-configuration isusedtoautomaticallyconfigurethe requiredconfigurationfortheapplication. Forexample,ifyouhaveadatasourcebeanpresentintheclasspathof theapplication,thenitautomaticallyconfigurestheJDBCtemplate. Withthehelpofauto-configuration,youcancreateaJavaapplication inaneasyway,asitautomaticallyconfigurestherequiredbeans, controllers,etc. Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration
Question 23 Spring Boot Interview Questions www.edureka.co Todisabletheauto-configuration property,youhaveto excludeattributeof @EnableAutoConfiguration,inthe scenariowhereyoudonotwantittobeapplied. Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfig uration.class}) Iftheclassisnotontheclasspath,thentoexcludetheauto- configuration,youhavetomentionthefollowingcode: @EnableAutoConfiguration(excludeName={Sample.class})
Question 23 Spring Boot Interview Questions www.edureka.co Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration Apartfromthis,SpringBootalsoprovidesthefacilitytoexcludelistof auto-configurationclassesbyusingthespring.autoconfigure.exclude property.Youcangoforward,andadditeitherintothe application.properties oraddmultipleclasseswithcomma-separated.
Whatarethedifferencesbetween @SpringBootApplication and @EnableAutoConfiguration annotation? Question 24 Spring Boot Interview Questions www.edureka.co
Question 24 Spring Boot Interview Questions www.edureka.co Whatarethedifferencesbetween @SpringBootApplication and @EnableAutoConfiguration annotation? ✓ Usedinthemainclassorbootstrapclass ✓ Itisacombinationof@Configuration,@ComponentScan and @EnableAutoConfiguration annotations. @SpringBootApplication@SpringBootApplication ✓ Usedtoenableauto-configuration andcomponentscanninginyour project ✓ Itisacombinationof@Configurationand@ComponentScan annotations @EnableAutoConfiguration@EnableAutoConfiguration V/S
WhatarethestepstodeploySpring BootwebapplicationsasJARand WARfiles? Question 25 Spring Boot Interview Questions www.edureka.co
Question 25 Spring Boot Interview Questions www.edureka.co ✓ TodeployaSpringBootwebapplication,youjusthavetoaddthe followingplugininthepom.xmlfilein,justaddapluginelement topom.xml: @SpringBootApplication@SpringBootApplication WhatarethestepstodeploySpring BootwebapplicationsasJARand WARfiles? @<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
Question 25 Spring Boot Interview Questions www.edureka.co ✓ Thepackagingelementinthepom.xmlfilemustbesettojartobuilda JARfileasbelow: @SpringBootApplication@SpringBootApplication WhatarethestepstodeploySpring BootwebapplicationsasJARand WARfiles? <packaging>jar</packaging> <packaging>war</packaging>
Canyougiveanexamplefor ReadOnlyastrueinTransaction management? Question 26 Spring Boot Interview Questions www.edureka.co
Question 26 Spring Boot Interview Questions www.edureka.co Considerascenario,whereyouhavetoreaddatafromthedatabase. Forexample,letussayyouhaveacustomerdatabase,andyouwantto readthecustomerdetailssuchascustomerID,customername,and customeremailID. Todothat,youwillsetread-onlyonthetransactionaswedonotwantto checkforthechangesintheentities. Canyougiveanexamplefor ReadOnlyastrueinTransaction management?
Canyouexplainhowtodeploytoa different serverwithSpringBoot? Question 27 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co TodeployadifferentserverwithSpringBoot,followthebelowsteps: Canyouexplainhowtodeploytoa different serverwithSpringBoot? Question 27 01 GenerateaWARfromtheproject 02 DeploytheWARfileontoyourfavouriteserver Question 27
Whatisthebestwaytoexpose customapplicationconfiguration withSpringBoot? Question 28 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co OnewaytoexposethecustomapplicationconfigurationinSpringBootis byusingthe@Value annotation. But,theonlyproblemwiththisannotationisthatalltheconfiguration valueswillbedistributedthroughouttheapplication. Instead,youcanuseacentralized approach. Bycentralizedapproach,Imeanthatyoucandefineaconfiguration componentusingthe@ConfigurationProperties asfollows: Question 28 Whatisthebestwaytoexpose customapplicationconfiguration withSpringBoot? <packaging>@Component @ConfigurationProperties("example") public class SampleConfiguration { private int num; private boolean value; private String msg;</packaging>
Spring Boot Interview Questions www.edureka.co Accordingtotheabovesnippet,thevaluesconfiguredin application.properties willbeasfollows: Question 28 Whatisthebestwaytoexpose customapplicationconfiguration withSpringBoot? example.num: 100 example.value: true example.msg: Dynamic Message
Canwecreateanon-web applicationinSpringBoot? Question 29 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 29 Canwecreateanon-web applicationinSpringBoot? Yes,wecancreate a non-web applicationbyremovingthe webdependenciesfromclasspathalongwithchangingthewaySpring Boot creates the application context.
Whatarethestepstoconnectan externaldatabaselikeMySQLor Oracle? Question 30 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 30 Toconnectanexternaldatabase,youhavetofollowthebelowsteps: ➢ StartbyaddingthedependencyforMySQLConnectortopom.xml ➢ ThenremoveH2Dependencyfrompom.xml ➢ Now,setupyourMySQLdatabaseandconfigureyourconnectiontothe MySQLdatabase ➢ Restartyourproject Whatarethestepstoconnectan externaldatabaselikeMySQLor Oracle?
MentiontheadvantagesofYAML filethanPropertiesfileandthe different waystoloadYAMLfilein Springboot Question 31 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 31 TheadvantagesoftheYAMLfilethanapropertiesfileisthatthedatais storedinahierarchicalformat. So,itbecomesveryeasyforthedeveloperstodebugifthereisanissue. TheSpringApplicationclasssupportstheYAMLfileasanalternative to propertieswheneveryouusetheSnakeYAMLlibraryonyourclasspath. The different ways to load a YAML file in Spring Boot is as follows: ➢ UseYamlMapFactoryBeantoloadYAMLasaMap ➢ UseYamlPropertiesFactoryBean toloadYAMLasProperties MentiontheadvantagesofYAML filethanPropertiesfileandthe different waystoloadYAMLfilein Springboot
HowisHibernatechosenasthe defaultimplementationforJPA withoutanyconfiguration? Question 32 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 32 WhenweusetheSpring Boot Auto Configuration, automaticallythespring-boot-starter-data- jpadependencygetsaddedtothepom.xmlfile. Now,sincethisdependencyhasatransitivedependencyonJPAand Hibernate,Spring Boot automatically auto- configures Hibernate as the default implementation for JPA,wheneveritseesHibernatein theclasspath. HowisHibernatechosenasthe defaultimplementationforJPA withoutanyconfiguration?
WhatdoyouunderstandbySpring DataREST? Question 33 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 33 Spring Data REST isusedtoexposetheRESTfulresources aroundSpringDatarepositories. Considerthefollowingexample: WhatdoyouunderstandbySpring DataREST? @RepositoryRestResource(collectionResourceRel = "sample", path = "sample") public interface SampleRepository extends CustomerRepository<sample, Long> {
Spring Boot Interview Questions www.edureka.co Question 33 WhatdoyouunderstandbySpring DataREST? ToexposetheRESTservices,youcanusethePOSTmethodinthe followingway: { "customerid": "Rohit", "customeremailid": "customer1@abc.com" } ResponseContent: { "customerid": "Rohit", "customeremailid": "customer1@abc.com", "_links": { "self": { "href": "http://localhost:8080/sample/1" }, "sample": { "href": "http://localhost:8080/sample/1" }}
Whatisthedifferencebetween RequestMappingandGetMapping? Question 34 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 34 The@GetMappingisacomposedannotationthatactsasashortcut for@RequestMapping(method =RequestMethod.GET). Boththesemethodssupporttheconsumes.Theconsumeoptionsare: consumes=“text/plain” consumes={“text/plain”,“application/*”} Whatisthedifferencebetween RequestMappingandGetMapping?
Inwhichlayer,shouldtheboundary ofatransactionstart? Question 35 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 35 Theboundary of the transaction shouldstartfromthe ServiceLayersincethelogicforthebusinesstransactionispresentin thislayeritself. Inwhichlayer,shouldtheboundary ofatransactionstart?
Howdoespath=”sample”, collectionResourceRel=”sample” workwithSpringDataRest? Question 36 Spring Boot Interview Questions www.edureka.co
Spring Boot Interview Questions www.edureka.co Question 36 Howdoespath=”sample”, collectionResourceRel=”sample” workwithSpringDataRest? @RepositoryRestResource(collectionResourceRel = "sample", path = "sample") public interface SampleRepository extends PagingAndSortingRepository<Sample, Long> ➢ path – This section is used to mention the segment under whichtheresourceistobeexported. ➢ collectionResourceRel – This value is used to generatelinkstothecollectionresource.
Question 37 Spring Boot Interview Questions www.edureka.co Explainhowtoregisteracustom auto-configuration.
Spring Boot Interview Questions www.edureka.co Question 37 Explainhowtoregisteracustom auto-configuration. Inordertoregisteranauto-configurationclass,youhavetomention the fully-qualified name underthe @EnableAutoConfiguration key META- INF/spring. factories file. Also,ifwebuildthewithmaven,thenthisfileshouldbeplacedinthe resources/META-INT directory.
Question 38 Spring Boot Interview Questions www.edureka.co HowdoyouConfigureLog4jfor logging?
Spring Boot Interview Questions www.edureka.co Question 38 SinceSpringBootsupports Log4j2 for logging a configuration,youhavetoexclude Logback and include Log4j2 for logging.Thiscanbeonlydoneifyouare usingthestartersproject. HowdoyouConfigureLog4jfor logging?
Question 39 Spring Boot Interview Questions www.edureka.co Mentionthedifferencesbetween WARandembeddedcontainers
Spring Boot Interview Questions www.edureka.co Question 39 HowdoyouConfigureLog4jfor logging? WARbenefitsaconsiderablemeasurefromSpringBoot WARWAR OnlyonecomponentofSpringBootandisutilizedduringimprovements EmbeddedContainersEmbeddedContainers V/S
Question 40 Spring Boot Interview Questions www.edureka.co Whatdoyouthinkistheneedfor Profiles?
Spring Boot Interview Questions www.edureka.co Question 40 ProfilesinSpringprovidesawaytosegregatethepartsofthe applicationconfigurationandmakesitavailableinenvironments.So, basically,any@Component or a @Configuration can bemarkedwitha@Profiletolimitasitisloaded. Whatdoyouthinkistheneedfor Profiles?
Question 41 Spring Boot Interview Questions www.edureka.co Whatdoyouthinkistheneedfor Profiles?
Spring Boot Interview Questions www.edureka.co Question 41 ThestepstoaddacustomJScodewithSpringBootareas follows: ✓ Createafoldercalledstaticundertheresourcesfolder ✓ Inthisfolder,youcanputthestaticcontentinthatfolder Whatarethestepstoaddacustom JScodewithSpringBoot? Note:Justincase,thebrowserthrowsanunauthorizederror,youeither disablethesecurityorsearchforthepasswordinthelogfile,andeventually passitintherequestheader.
Question 42 Spring Boot Interview Questions www.edureka.co Howtoinstructanauto- configurationtobackoffwhena beanexists?
Spring Boot Interview Questions www.edureka.co Question 42 Toinstructanauto-configuration classtobackoffwhenabean exists,youhavetousethe @ConditionalOnMissingBean annotation. Theattributesofthisannotationareasfollows: ➢ value:Thisattributestoresthetypeofbeanstobechecked ➢ name:Thisattributestoresthenameofbeanstobechecked Howtoinstructanauto- configurationtobackoffwhena beanexists?
Question 43 Spring Boot Interview Questions www.edureka.co WhyisSpringDataRESTnot recommendedinreal-world applications?
Spring Boot Interview Questions www.edureka.co Question 43 Spring Data REST isnotrecommendedinreal-world applicationsasyouareexposingyourdatabaseentities directly asRESTservices. WhiledesigningRESTfulservices,thetwomostimportantthingsthat weconsideristhedomainmodelandtheconsumers. But,whileusingSpringDataREST,noneoftheseparametersare considered.Theentitiesaredirectlyexposed. UseSpringDataREST,for the initial evolution of the project. WhyisSpringDataRESTnot recommendedinreal-world applications?
Question 44 Spring Boot Interview Questions www.edureka.co Whatistheerroryouseeif H2is notintheclasspath?
Spring Boot Interview Questions www.edureka.co Question 44 IfH2isnotpresentintheclasspath,thenyouseethefollowing error: Whatistheerroryouseeif H2is notintheclasspath? Cannot determine embedded database driver class for database type NONE
Spring Boot Interview Questions www.edureka.co Question 44 Whatistheerroryouseeif H2is notintheclasspath? Toresolvethiserror,addH2tothepom.xmlfile,andrestartyour server. Thefollowingcodesnippetcanbeaddedtoaddthedependency: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency>
Question 45 Spring Boot Interview Questions www.edureka.co Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot?
Spring Boot Interview Questions www.edureka.co Question 45 Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot? Since its a known fact that a Profile is nothing but a key to identify an environment lets consider the following two profiles in the example: •dev •Prod Consider the following properties present in the application propertiesfile: example.number: 100 example.value: true example.msg: Dynamic Message
Spring Boot Interview Questions www.edureka.co Question 45 Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot? Now, say you want to customize the application.properties for dev profile, then you need to create a file with name application- dev.properties and override the properties that you want to customize. Youcanmentionthefollowingcode: example.msg: Dynamic Message in Dev Similarly,ifyouwanttocustomizetheapplication.properties forprod profile,thenyoucanmentionthefollowingcodesnippet: example.msg: Dynamic Message in Prod
Spring Boot Interview Questions www.edureka.co Question 45 Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot? Once you are done with the profile-specific configuration, you havetosettheactive profileinanenvironment. Todothat, either youcan: ✓ Use-Dspring.profiles.active=prod in arguments ✓ Usespring.profiles.active=prodinapplication.propertiesfile
Question 46 Spring Boot Interview Questions www.edureka.co Mentionthedependenciesneeded tostartupaJPAApplicationand connecttoin-memorydatabaseH2 withSpringBoot?
Spring Boot Interview Questions www.edureka.co Question 46 Mentionthedependenciesneeded tostartupaJPAApplicationand connecttoin-memorydatabaseH2 withSpringBoot? web starter H2 data JPA starter ThedependenciesareneededtostartupaJPAApplicationandconnect toin-memorydatabaseH2withSpringBoot
Spring Boot Interview Questions www.edureka.co Question 46 Mentionthedependenciesneeded tostartupaJPAApplicationand connecttoin-memorydatabaseH2 withSpringBoot? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data- jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency>
Question 47 Spring Boot Interview Questions www.edureka.co WhatdoyouunderstandbySpring Bootsupportsrelaxedbinding?
Spring Boot Interview Questions www.edureka.co Question 47 WhatdoyouunderstandbySpring Bootsupportsrelaxedbinding? Relaxed binding,isawayinwhich,thepropertynamedoesnot needtomatchthekeyoftheenvironmentproperty. InSpringBoot,relaxedbindingisapplicabletothetype-safebindingof theconfigurationproperties.
Spring Boot Interview Questions www.edureka.co Question 47 WhatdoyouunderstandbySpring Bootsupportsrelaxedbinding? Forexample,ifapropertyinabeanclasswiththe @ConfigurationProperties annotationisused sampleProp,thenitcanbeboundedtoanyofthefollowingenvironment properties: ❑sampleProp ❑sample_Prop ❑sample_Prop ❑SAMPLE_PROP
Question 48 Spring Boot Interview Questions www.edureka.co Whereisthedatabaseconnection informationspecifiedandhowdoes itautomaticallyconnecttoH2?
Spring Boot Interview Questions www.edureka.co Question 48 Whereisthedatabaseconnection informationspecifiedandhowdoes itautomaticallyconnecttoH2? ItisbecauseoftheSpring Boot Autoconfiguration that,configuresthedependenciesoftheapplication. So,thedatabaseconnection information,andautomaticallyconnecting thedatabasetoH2isdonebytheauto-configurationproperty.
Question 49 Spring Boot Interview Questions www.edureka.co WhatisthenameofthedefaultH2 databaseconfiguredbySpring Boot?
Spring Boot Interview Questions www.edureka.co Question 49 WhatisthenameofthedefaultH2 databaseconfiguredbySpring Boot? ThenameofthedefaultH2databaseistestdb spring.datasource.name=testdb # Name of the datasource. Note:Justin-caseifyouareusingH2in-memorydatabase,thenexactly thatisthenameofSpringBootwhichisusedtosetupyourH2database.
Question 50 Spring Boot Interview Questions www.edureka.co Doyouthink,youcanusejetty insteadoftomcatinspring-boot- starter-web?
Spring Boot Interview Questions www.edureka.co Question 50 Yes,wecanusejettyinsteadoftomcatinspring-boot-starter-web,by removingtheexistingdependencyandincludingthefollowing: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- jetty</artifactId> </dependency> Doyouthink,youcanusejetty insteadoftomcatinspring-boot- starter-web?
www.edureka.co

Spring Boot Interview Questions | Edureka

  • 2.
    Why should youuse Spring Boot? www.edureka.co
  • 3.
    Why should youuse Spring Boot? Stability Based on JVM Open Source Cloud- Native Connectivity Flexibility www.edureka.co
  • 4.
    Java Spring BootDeveloper Salary Trend www.edureka.co
  • 5.
  • 6.
  • 7.
    Question 1 Whatarethedifferencesbetween SpringandSpringBoot? Spring SpringBoot AwebapplicationframeworkbasedonJavaAmoduleofSpring Providestoolsandlibrariestocreate customizedwebapplications UsedtocreateaSpringapplicationproject whichcanjustrun/execute SpringismorecomplexthanSpringBoot SpringBootislesscomplexthantheSpring framework Takesanunopinionatedview Takesanopinionatedviewofaplatform Spring Boot Interview Questions www.edureka.co
  • 8.
  • 9.
    Question 2 Usedtocreate stand-aloneSpring-based applications whichyoucanjustrun Spring Boot isaSpringmodulewhichaimstosimplifytheuseofthe SpringframeworkforJava development. Spring Boot Interview Questions www.edureka.co ❑ Auto-dependencyResolution ❑ EmbeddedHTTPservers ❑ Auto-configuration ❑ Managementendpoints ❑ SpringBootCLI WhatisSpringBootandmention theneedforit? AimsatRapid Application Development SpringBootframeworkcomeswith
  • 10.
  • 11.
    Question 3 Spring Boot InterviewQuestions www.edureka.co WhataretheadvantagesofSpring Boot? Advantages of Spring Boot 01 Provides autoconfiguration to load a set of default configuration for a quick start of the application 02Creates stand-alone applications with a range of non-functional features that are common to large classes of project 03 Spring Boot comes with embedded tomcat, servlet containers jetty to avoid the usage of WAR files 04Spring Boot provides an opinionated view to reduce the developer effort and simplify maven configurations
  • 12.
    Question 3 Spring Boot InterviewQuestions www.edureka.co WhataretheadvantagesofSpring Boot? Advantages of Spring Boot 05 Provides CLI tool to develop and test applications 06Comes with Spring Boot starters to ensure dependency management and also provides various security metrics 07 Consists of a wide range of APIs for monitoring and managing applications in dev and prod. 08Integrates with Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security easily by avoiding boilerplate code.
  • 13.
  • 14.
    Question 4 Spring Boot InterviewQuestions www.edureka.co MentionafewfeaturesofSpring Boot Spring CLISpring CLISpring CLI SpringBootCLIallowsyou toGroovyforwritingSpringboot applicationandavoids boilerplatecode. Starter DependencyStarter DependencyStarter Dependency Withthehelpofthisfeature, SpringBootaggregatescommon dependenciestogetherand eventuallyimprovesproductivity Spring InitializerSpring InitializerSpring Initializer Thisisbasicallyaweb application,whichcan createan internalprojectstructureforyou. Auto-configurationAuto-configurationAuto-configuration Theauto-configurationfeatureof SpringBoothelpsinloadingthe defaultconfigurationsaccordingto theprojectyouareworkingon Spring ActuatorSpring ActuatorSpring Actuator Thisfeatureprovideshelpwhile runningSpringBootapplications. Logging and SecurityLogging and SecurityLogging and Security ThisfeatureofSpringBoot,ensures thatalltheapplicationsmadeusing SpringBootareproperlysecured withoutanyhassle.
  • 15.
  • 16.
    Question 5 Spring Boot InterviewQuestions www.edureka.co ExplainhowtocreateSpringBoot applicationusingMaven TherearevariousapproachestocreateaSpringBootapplication using maven: ❑Spring Boot CLI ❑Spring Boot Project Wizard ❑Spring Boot Initializer ❑Spring Maven Project
  • 17.
  • 18.
    Question 6 Spring Boot InterviewQuestions www.edureka.co Whatarethethepossiblesources ofexternalconfiguration? Application Properties Command Line Properties Profile Specific Properties MostPossibleSourcesOfExternalConfiguration
  • 19.
  • 20.
    Question 7 Spring Boot InterviewQuestions www.edureka.co Canyouexplainwhathappensin thebackgroundwhenaSpringBoot Applicationis“RunasJava Application”? WhenaSpring Boot application isexecutedas“Run as Java application”,thenitautomatically launches up the tomcat serverassoonasitsees,that youaredevelopingawebapplication.
  • 21.
  • 22.
    Question 8 WhataretheSpringBootstarters andwhatareavailablethe starters? Spring Boot InterviewQuestions www.edureka.co Spring Boot starters areasetofconvenient dependency managementproviderswhichcanbeusedintheapplicationtoenable dependencies. Thesestartersmakedevelopmenteasyandrapid.Allthe availablestarterscomeunderthe org.springframework.boot group.
  • 23.
    Question 8 WhataretheSpringBootstarters andwhatareavailablethe starters? Spring Boot InterviewQuestions www.edureka.co 01 spring-boot-starter 02 spring-boot-starter-jdbc 03 spring-boot-starter-web 04 spring-boot-starter-data-jpa 05 spring-boot-starter-security 06 spring-boot-starter-aop 07 spring-boot-starter-test
  • 24.
    Question 9 Spring Boot InterviewQuestions www.edureka.co ExplainSpringActuatorandits advantages
  • 25.
    Question 9 ExplainSpringActuatorandits advantages Spring Boot InterviewQuestions www.edureka.co Spring Actuator isacoolfeatureofSpring Boot withthe helpofwhichyoucanseewhatishappeninginsidearunning application. TheSpringActuatorprovidesaveryeasywaytoaccesstheproduction- readyREST points andfetchallkindsofinformationfromtheweb. ThesepointsaresecuredusingSpring Security’s content negotiation strategy.
  • 26.
    Question 10 Spring Boot InterviewQuestions www.edureka.co WhatisSpringBootdependency management?
  • 27.
    Question 10 Spring Boot InterviewQuestions www.edureka.co WhatisSpringBootdependency management? Spring Boot dependency management isusedtomanage dependenciesandconfigurationautomaticallywithoutyouspecifyingthe versionforanyofthatdependencies.
  • 28.
    Question 11 Spring Boot InterviewQuestions www.edureka.co Mentiontheminimum requirementsforaSpringboot System
  • 29.
    Question 11 Spring Boot InterviewQuestions www.edureka.co Mentiontheminimum requirementsforaSpringboot System Spring Boot 2.1.7.Release requires ✓ Java8+ ✓ SpringFramework5.1.9+ Explicit Build Support ✓ Maven3.3+ ✓ Gradle4.4+ Servlet Container Support ✓ Tomcat9.0–ServletVersion4.0 ✓ Jetty9.4– ServletVersion3.1 ✓ Undertow2.0–Servlet Version4.0
  • 30.
    Question 12 Spring Boot InterviewQuestions www.edureka.co Whatisthymeleafandhowtouse thymeleaf?
  • 31.
    Question 12 Spring Boot InterviewQuestions www.edureka.co Thymeleaf is a server-side Java template engine used forwebapplications. Itaims to bringnaturaltemplatefor yourwebapplication andcan integrate well with Spring Framework and HTML5 Java web applications. Whatisthymeleafandhowtouse thymeleaf? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- thymeleaf</artifactId> </dependency>
  • 32.
    Question 13 Spring Boot InterviewQuestions www.edureka.co Canwechangetheportof embeddedTomcatserverinSpring Boot?
  • 33.
    Question 13 Spring Boot InterviewQuestions www.edureka.co Canwechangetheportof embeddedTomcatserverinSpring Boot? Yes,wecanchangetheportoftheembeddedtomcatserverbyusing theapplication properties file. Inthisfile,youhavetoaddapropertyof“server.port”andassignitto anyportyouwishto. Forexample,ifyouwanttoassignitto8081,thenyouhavetomention server.port=8081 Onceyoumentiontheportnumber,theapplicationpropertiesfilewill beautomaticallyloadedbySpringBootandtherequired configurationswillbeappliedontotheapplication.
  • 34.
    Question 14 Spring Boot InterviewQuestions www.edureka.co WhatistheneedforSpringBoot DevTools?
  • 35.
    Question 14 Spring Boot InterviewQuestions www.edureka.co Spring Boot Dev Tools isanelaboratedsetoftools andaimstomaketheprocessofdevelopinganapplicationeasier. Iftheapplicationrunsintheproduction,thenthismoduleis automaticallydisabled,repackagingofarchivesarealso excludedbydefault. So,theSpring Boot Developer Tools applies propertiestotherespectivedevelopmentenvironments. WhatistheneedforSpringBoot DevTools?
  • 36.
    Question 14 Spring Boot InterviewQuestions www.edureka.co WhatistheneedforSpringBoot DevTools?
  • 37.
    Question 14 Spring Boot InterviewQuestions www.edureka.co Spring Boot Dev Tools isanelaboratedsetoftoolsandaims tomaketheprocessofdevelopinganapplicationeasier. Iftheapplicationrunsintheproduction,thenthismoduleisautomatically disabled,repackagingofarchivesarealsoexcludedbydefault. WhatistheneedforSpringBoot DevTools? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- thymeleaf</artifactId> </dependency>
  • 39.
    Question 15 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstocreatea SpringBootprojectusing Spring Initializer
  • 40.
    Question 15 Spring Boot InterviewQuestions www.edureka.co Spring Initializer isawebtoolprovidedbySpring.Withthe helpofthistool,youcancreateSpringBootprojectsbyjust providingprojectdetails. Mentionthestepstocreatea SpringBootprojectusing Spring Initializer
  • 41.
    Question 15 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstocreatea SpringBootprojectusing Spring Initializer ✓ Choose the maven project and the required dependencies. Then, fill the other required details like Group, Artifact, and then click on GenerateProject. ✓ Once the project is downloaded, extract the project on to your system ✓ Next, you have to import this project using the import option on the SpringToolSuiteIDE
  • 42.
    Question 16 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC
  • 43.
    Question 16 Spring Boot InterviewQuestions www.edureka.co SpringBootstarterprojectsprovidetherequiredlibrariesto connecttheapplicationwithJDBC. So,forexample,ifyoujusthavetocreateanapplication and connectitwithMYSQLdatabase,youcanfollowthebelowsteps: Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 1: Create a database in MySQL CREATE DATABASE example; Step 2: Create a table inside this database CREATE TABLE customers(customerid INT PRIMARY KEY NOT NULL AUTO_INCREMENT, customername VARCHAR(255));
  • 44.
    Question 16 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 3: Create a Spring Boot project and provide the required details Step 4: Add JDBC, MySQL and web dependencies. spring.datasource.url=jdbc:mysql://localhost:3306/e xample spring.datasource.username=root spring.datasource.password=mysql spring.jpa.hibernate.ddl-auto=create-drop Step 5: Once the project is created, you have to configure the database into application properties.
  • 45.
    Question 16 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 6: The main application.java class should have the following code: package com.edureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootAp plication; @SpringBootApplication public class SampleApplication { public static void main(String[] args) { SpringApplication.run(SampleApplication.class, args); } }
  • 46.
    Question 16 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 7: You have to create a controller to handle the HTTP requests, by mentioning the following code: package com.edureka; Import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.RestController; @RestController public class JdbcController { @Autowired JdbcTemplate jdbc; @RequestMapping("/insert") public String index(){ jdbc.execute("insert into customers(name)values('Aryya')"); return "Data Entry Successful"; } }
  • 47.
    Question 16 Spring Boot InterviewQuestions www.edureka.co Mentionthestepstoconnect SpringBootapplicationtoa databaseusingJDBC Step 8: Finally execute this project as a Java application. Step 9: Open the URL (localhost:8080/insert), and you will see the output as data entry successful. You can also go forward and check if the data is entered into the table.
  • 48.
    Question 17 Spring Boot InterviewQuestions www.edureka.co HowtoenableHTTP/2supportin SpringBoot
  • 49.
    Question 17 Spring Boot InterviewQuestions www.edureka.co HowtoenableHTTP/2supportin SpringBoot YoucanenabletheHTTP/2supportinSpringBootby: server.http2.enabled=true
  • 50.
    Question 18 Spring Boot InterviewQuestions www.edureka.co Whatarethe @RequestMapping and @RestControllerannotationin SpringBootusedfor?
  • 51.
    Question 18 Spring Boot InterviewQuestions www.edureka.co Whatarethe @RequestMapping and @RestControllerannotationin SpringBootusedfor? ✓ Thisannotationisusedtoprovidetheroutinginformationandtellsto SpringthatanyHTTPrequestmustbemappedtotherespective method. ✓ Tousethisannotation,youhavetoimport org.springframework.web.bind.annotation.RequestMapping; @RequestMapping@RequestMapping ✓ Thisannotationisusedtoprovidetheroutinginformationandtellsto SpringthatanyHTTPrequestmustbemappedtotherespective method. ✓ Tousethisannotation, youhavetoimport org.springframework.web.bind.annotation.RequestMapping; @RestController@RestController
  • 52.
    Question 18 Spring Boot InterviewQuestions www.edureka.co Whatarethe @RequestMapping and @RestControllerannotationin SpringBootusedfor? package com.edureka; import org.springframework.web.bind.annotation.RequestMapp ing; import org.springframework.web.bind.annotation.RestControl ler; @RestController public class SampleController { @RequestMapping("/example") public String example(){ return"Welcome To Edureka"; } } Consideryouhaveamethodexample()whichshouldmapwith/exampleURL.
  • 53.
    Question 19 Spring Boot InterviewQuestions www.edureka.co WhatisSpringBootCLIandhowto executetheSpringBootproject usingbootCLI?
  • 54.
    Question 19 Spring Boot InterviewQuestions www.edureka.co SpringBootCLIisatoolsupportedbytheofficial SpringFramework.The stepstoexecuteaSpringBootprojectareasfollows: ➢ DownloadtheCLItoolfromtheofficialsiteandextractthezipfile.The binfolderpresentintheSpringsetupisusedtoexecutetheSpring Bootapplication. ➢ SinceSpringBootCLIexecutesgroovyfiles,youneedtocreatea groovyfileforSpringBootapplication.So,todothat,openterminaland changethecurrentdirectorytobinfolder. WhatisSpringBootCLIandhowto executetheSpringBootproject usingbootCLI?
  • 55.
    Question 19 Spring Boot InterviewQuestions www.edureka.co Createacontrollerasfollows: WhatisSpringBootCLIandhowto executetheSpringBootproject usingbootCLI? @RestController public class Sample { @RequestMapping("/example") String index(){ <h1>"Welcome To Edureka"</h1>; } } Executethegroovyfilebymentioning ./spring run Sample.groovy;
  • 56.
    Question 20 Spring Boot InterviewQuestions www.edureka.co Whatarethedifferencesbetween JPAandHibernate?
  • 57.
    Question 20 Spring Boot InterviewQuestions www.edureka.co Whatarethedifferencesbetween JPAandHibernate? JPAisaDataAccessAbstractionusedtoreducetheamountofboilerplate code JPAJPA HibernateisanimplementationofJavaPersistenceAPIandoffers benefitsofloosecoupling HibernateHibernate V/S
  • 58.
  • 59.
    Question 21 Spring Boot InterviewQuestions www.edureka.co TocreateacustomendpointinSpringBoot2.x,youcanusethe @Endpoint annotation. SpringBootalsoexposesendpointsusing@WebEndpointor, @WebEndpointExtensionoverHTTPwiththehelp ofSpringMVC,Jerseyetc. Howcanwecreateacustom endpointinSpringBootActuator?
  • 60.
  • 61.
    Question 22 Spring Boot InterviewQuestions www.edureka.co Spring Data aimstomakeiteasyforthedeveloperstouse relationalandnon-relationaldatabases,cloud-baseddataservices, andotherdataaccesstechnologies. So,basically,itmakesiteasyfordataaccessandstillretainsthe underlyingdata. WhatdoyouunderstandbySpring Data?
  • 62.
  • 63.
    Question 23 Spring Boot InterviewQuestions www.edureka.co Auto-configuration isusedtoautomaticallyconfigurethe requiredconfigurationfortheapplication. Forexample,ifyouhaveadatasourcebeanpresentintheclasspathof theapplication,thenitautomaticallyconfigurestheJDBCtemplate. Withthehelpofauto-configuration,youcancreateaJavaapplication inaneasyway,asitautomaticallyconfigurestherequiredbeans, controllers,etc. Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration
  • 64.
    Question 23 Spring Boot InterviewQuestions www.edureka.co Todisabletheauto-configuration property,youhaveto excludeattributeof @EnableAutoConfiguration,inthe scenariowhereyoudonotwantittobeapplied. Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfig uration.class}) Iftheclassisnotontheclasspath,thentoexcludetheauto- configuration,youhavetomentionthefollowingcode: @EnableAutoConfiguration(excludeName={Sample.class})
  • 65.
    Question 23 Spring Boot InterviewQuestions www.edureka.co Whatdoyouunderstandbyauto- configurationinSpringBootand howtodisablethe auto- configuration Apartfromthis,SpringBootalsoprovidesthefacilitytoexcludelistof auto-configurationclassesbyusingthespring.autoconfigure.exclude property.Youcangoforward,andadditeitherintothe application.properties oraddmultipleclasseswithcomma-separated.
  • 66.
  • 67.
    Question 24 Spring Boot InterviewQuestions www.edureka.co Whatarethedifferencesbetween @SpringBootApplication and @EnableAutoConfiguration annotation? ✓ Usedinthemainclassorbootstrapclass ✓ Itisacombinationof@Configuration,@ComponentScan and @EnableAutoConfiguration annotations. @SpringBootApplication@SpringBootApplication ✓ Usedtoenableauto-configuration andcomponentscanninginyour project ✓ Itisacombinationof@Configurationand@ComponentScan annotations @EnableAutoConfiguration@EnableAutoConfiguration V/S
  • 68.
  • 69.
    Question 25 Spring Boot InterviewQuestions www.edureka.co ✓ TodeployaSpringBootwebapplication,youjusthavetoaddthe followingplugininthepom.xmlfilein,justaddapluginelement topom.xml: @SpringBootApplication@SpringBootApplication WhatarethestepstodeploySpring BootwebapplicationsasJARand WARfiles? @<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
  • 70.
    Question 25 Spring Boot InterviewQuestions www.edureka.co ✓ Thepackagingelementinthepom.xmlfilemustbesettojartobuilda JARfileasbelow: @SpringBootApplication@SpringBootApplication WhatarethestepstodeploySpring BootwebapplicationsasJARand WARfiles? <packaging>jar</packaging> <packaging>war</packaging>
  • 71.
  • 72.
    Question 26 Spring Boot InterviewQuestions www.edureka.co Considerascenario,whereyouhavetoreaddatafromthedatabase. Forexample,letussayyouhaveacustomerdatabase,andyouwantto readthecustomerdetailssuchascustomerID,customername,and customeremailID. Todothat,youwillsetread-onlyonthetransactionaswedonotwantto checkforthechangesintheentities. Canyougiveanexamplefor ReadOnlyastrueinTransaction management?
  • 73.
  • 74.
    Spring Boot Interview Questions www.edureka.co TodeployadifferentserverwithSpringBoot,followthebelowsteps: Canyouexplainhowtodeploytoa differentserverwithSpringBoot? Question 27 01 GenerateaWARfromtheproject 02 DeploytheWARfileontoyourfavouriteserver Question 27
  • 75.
  • 76.
    Spring Boot Interview Questions www.edureka.co OnewaytoexposethecustomapplicationconfigurationinSpringBootis byusingthe@Valueannotation. But,theonlyproblemwiththisannotationisthatalltheconfiguration valueswillbedistributedthroughouttheapplication. Instead,youcanuseacentralized approach. Bycentralizedapproach,Imeanthatyoucandefineaconfiguration componentusingthe@ConfigurationProperties asfollows: Question 28 Whatisthebestwaytoexpose customapplicationconfiguration withSpringBoot? <packaging>@Component @ConfigurationProperties("example") public class SampleConfiguration { private int num; private boolean value; private String msg;</packaging>
  • 77.
    Spring Boot Interview Questions www.edureka.co Accordingtotheabovesnippet,thevaluesconfiguredin application.propertieswillbeasfollows: Question 28 Whatisthebestwaytoexpose customapplicationconfiguration withSpringBoot? example.num: 100 example.value: true example.msg: Dynamic Message
  • 78.
  • 79.
    Spring Boot Interview Questions www.edureka.co Question29 Canwecreateanon-web applicationinSpringBoot? Yes,wecancreate a non-web applicationbyremovingthe webdependenciesfromclasspathalongwithchangingthewaySpring Boot creates the application context.
  • 81.
  • 82.
    Spring Boot Interview Questions www.edureka.co Question30 Toconnectanexternaldatabase,youhavetofollowthebelowsteps: ➢ StartbyaddingthedependencyforMySQLConnectortopom.xml ➢ ThenremoveH2Dependencyfrompom.xml ➢ Now,setupyourMySQLdatabaseandconfigureyourconnectiontothe MySQLdatabase ➢ Restartyourproject Whatarethestepstoconnectan externaldatabaselikeMySQLor Oracle?
  • 83.
  • 84.
    Spring Boot Interview Questions www.edureka.co Question31 TheadvantagesoftheYAMLfilethanapropertiesfileisthatthedatais storedinahierarchicalformat. So,itbecomesveryeasyforthedeveloperstodebugifthereisanissue. TheSpringApplicationclasssupportstheYAMLfileasanalternative to propertieswheneveryouusetheSnakeYAMLlibraryonyourclasspath. The different ways to load a YAML file in Spring Boot is as follows: ➢ UseYamlMapFactoryBeantoloadYAMLasaMap ➢ UseYamlPropertiesFactoryBean toloadYAMLasProperties MentiontheadvantagesofYAML filethanPropertiesfileandthe different waystoloadYAMLfilein Springboot
  • 85.
  • 86.
    Spring Boot Interview Questions www.edureka.co Question32 WhenweusetheSpring Boot Auto Configuration, automaticallythespring-boot-starter-data- jpadependencygetsaddedtothepom.xmlfile. Now,sincethisdependencyhasatransitivedependencyonJPAand Hibernate,Spring Boot automatically auto- configures Hibernate as the default implementation for JPA,wheneveritseesHibernatein theclasspath. HowisHibernatechosenasthe defaultimplementationforJPA withoutanyconfiguration?
  • 87.
  • 88.
    Spring Boot Interview Questions www.edureka.co Question33 Spring Data REST isusedtoexposetheRESTfulresources aroundSpringDatarepositories. Considerthefollowingexample: WhatdoyouunderstandbySpring DataREST? @RepositoryRestResource(collectionResourceRel = "sample", path = "sample") public interface SampleRepository extends CustomerRepository<sample, Long> {
  • 89.
    Spring Boot Interview Questions www.edureka.co Question33 WhatdoyouunderstandbySpring DataREST? ToexposetheRESTservices,youcanusethePOSTmethodinthe followingway: { "customerid": "Rohit", "customeremailid": "customer1@abc.com" } ResponseContent: { "customerid": "Rohit", "customeremailid": "customer1@abc.com", "_links": { "self": { "href": "http://localhost:8080/sample/1" }, "sample": { "href": "http://localhost:8080/sample/1" }}
  • 90.
  • 91.
    Spring Boot Interview Questions www.edureka.co Question34 The@GetMappingisacomposedannotationthatactsasashortcut for@RequestMapping(method =RequestMethod.GET). Boththesemethodssupporttheconsumes.Theconsumeoptionsare: consumes=“text/plain” consumes={“text/plain”,“application/*”} Whatisthedifferencebetween RequestMappingandGetMapping?
  • 92.
  • 93.
    Spring Boot Interview Questions www.edureka.co Question35 Theboundary of the transaction shouldstartfromthe ServiceLayersincethelogicforthebusinesstransactionispresentin thislayeritself. Inwhichlayer,shouldtheboundary ofatransactionstart?
  • 94.
  • 95.
    Spring Boot Interview Questions www.edureka.co Question36 Howdoespath=”sample”, collectionResourceRel=”sample” workwithSpringDataRest? @RepositoryRestResource(collectionResourceRel = "sample", path = "sample") public interface SampleRepository extends PagingAndSortingRepository<Sample, Long> ➢ path – This section is used to mention the segment under whichtheresourceistobeexported. ➢ collectionResourceRel – This value is used to generatelinkstothecollectionresource.
  • 96.
    Question 37 Spring Boot InterviewQuestions www.edureka.co Explainhowtoregisteracustom auto-configuration.
  • 97.
    Spring Boot Interview Questions www.edureka.co Question37 Explainhowtoregisteracustom auto-configuration. Inordertoregisteranauto-configurationclass,youhavetomention the fully-qualified name underthe @EnableAutoConfiguration key META- INF/spring. factories file. Also,ifwebuildthewithmaven,thenthisfileshouldbeplacedinthe resources/META-INT directory.
  • 98.
    Question 38 Spring Boot InterviewQuestions www.edureka.co HowdoyouConfigureLog4jfor logging?
  • 99.
    Spring Boot Interview Questions www.edureka.co Question38 SinceSpringBootsupports Log4j2 for logging a configuration,youhavetoexclude Logback and include Log4j2 for logging.Thiscanbeonlydoneifyouare usingthestartersproject. HowdoyouConfigureLog4jfor logging?
  • 100.
    Question 39 Spring Boot InterviewQuestions www.edureka.co Mentionthedifferencesbetween WARandembeddedcontainers
  • 101.
    Spring Boot Interview Questions www.edureka.co Question39 HowdoyouConfigureLog4jfor logging? WARbenefitsaconsiderablemeasurefromSpringBoot WARWAR OnlyonecomponentofSpringBootandisutilizedduringimprovements EmbeddedContainersEmbeddedContainers V/S
  • 102.
    Question 40 Spring Boot InterviewQuestions www.edureka.co Whatdoyouthinkistheneedfor Profiles?
  • 103.
    Spring Boot Interview Questions www.edureka.co Question40 ProfilesinSpringprovidesawaytosegregatethepartsofthe applicationconfigurationandmakesitavailableinenvironments.So, basically,any@Component or a @Configuration can bemarkedwitha@Profiletolimitasitisloaded. Whatdoyouthinkistheneedfor Profiles?
  • 104.
    Question 41 Spring Boot InterviewQuestions www.edureka.co Whatdoyouthinkistheneedfor Profiles?
  • 105.
    Spring Boot Interview Questions www.edureka.co Question41 ThestepstoaddacustomJScodewithSpringBootareas follows: ✓ Createafoldercalledstaticundertheresourcesfolder ✓ Inthisfolder,youcanputthestaticcontentinthatfolder Whatarethestepstoaddacustom JScodewithSpringBoot? Note:Justincase,thebrowserthrowsanunauthorizederror,youeither disablethesecurityorsearchforthepasswordinthelogfile,andeventually passitintherequestheader.
  • 106.
    Question 42 Spring Boot InterviewQuestions www.edureka.co Howtoinstructanauto- configurationtobackoffwhena beanexists?
  • 107.
    Spring Boot Interview Questions www.edureka.co Question42 Toinstructanauto-configuration classtobackoffwhenabean exists,youhavetousethe @ConditionalOnMissingBean annotation. Theattributesofthisannotationareasfollows: ➢ value:Thisattributestoresthetypeofbeanstobechecked ➢ name:Thisattributestoresthenameofbeanstobechecked Howtoinstructanauto- configurationtobackoffwhena beanexists?
  • 108.
    Question 43 Spring Boot InterviewQuestions www.edureka.co WhyisSpringDataRESTnot recommendedinreal-world applications?
  • 109.
    Spring Boot Interview Questions www.edureka.co Question43 Spring Data REST isnotrecommendedinreal-world applicationsasyouareexposingyourdatabaseentities directly asRESTservices. WhiledesigningRESTfulservices,thetwomostimportantthingsthat weconsideristhedomainmodelandtheconsumers. But,whileusingSpringDataREST,noneoftheseparametersare considered.Theentitiesaredirectlyexposed. UseSpringDataREST,for the initial evolution of the project. WhyisSpringDataRESTnot recommendedinreal-world applications?
  • 110.
    Question 44 Spring Boot InterviewQuestions www.edureka.co Whatistheerroryouseeif H2is notintheclasspath?
  • 111.
    Spring Boot Interview Questions www.edureka.co Question44 IfH2isnotpresentintheclasspath,thenyouseethefollowing error: Whatistheerroryouseeif H2is notintheclasspath? Cannot determine embedded database driver class for database type NONE
  • 112.
    Spring Boot Interview Questions www.edureka.co Question44 Whatistheerroryouseeif H2is notintheclasspath? Toresolvethiserror,addH2tothepom.xmlfile,andrestartyour server. Thefollowingcodesnippetcanbeaddedtoaddthedependency: <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency>
  • 114.
    Question 45 Spring Boot InterviewQuestions www.edureka.co Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot?
  • 115.
    Spring Boot Interview Questions www.edureka.co Question45 Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot? Since its a known fact that a Profile is nothing but a key to identify an environment lets consider the following two profiles in the example: •dev •Prod Consider the following properties present in the application propertiesfile: example.number: 100 example.value: true example.msg: Dynamic Message
  • 116.
    Spring Boot Interview Questions www.edureka.co Question45 Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot? Now, say you want to customize the application.properties for dev profile, then you need to create a file with name application- dev.properties and override the properties that you want to customize. Youcanmentionthefollowingcode: example.msg: Dynamic Message in Dev Similarly,ifyouwanttocustomizetheapplication.properties forprod profile,thenyoucanmentionthefollowingcodesnippet: example.msg: Dynamic Message in Prod
  • 117.
    Spring Boot Interview Questions www.edureka.co Question45 Whatisthewaytouseprofilesto configuretheenvironment- specificconfigurationwithSpring Boot? Once you are done with the profile-specific configuration, you havetosettheactive profileinanenvironment. Todothat, either youcan: ✓ Use-Dspring.profiles.active=prod in arguments ✓ Usespring.profiles.active=prodinapplication.propertiesfile
  • 118.
    Question 46 Spring Boot InterviewQuestions www.edureka.co Mentionthedependenciesneeded tostartupaJPAApplicationand connecttoin-memorydatabaseH2 withSpringBoot?
  • 119.
    Spring Boot Interview Questions www.edureka.co Question46 Mentionthedependenciesneeded tostartupaJPAApplicationand connecttoin-memorydatabaseH2 withSpringBoot? web starter H2 data JPA starter ThedependenciesareneededtostartupaJPAApplicationandconnect toin-memorydatabaseH2withSpringBoot
  • 120.
    Spring Boot Interview Questions www.edureka.co Question46 Mentionthedependenciesneeded tostartupaJPAApplicationand connecttoin-memorydatabaseH2 withSpringBoot? <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data- jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency>
  • 121.
    Question 47 Spring Boot InterviewQuestions www.edureka.co WhatdoyouunderstandbySpring Bootsupportsrelaxedbinding?
  • 122.
    Spring Boot Interview Questions www.edureka.co Question47 WhatdoyouunderstandbySpring Bootsupportsrelaxedbinding? Relaxed binding,isawayinwhich,thepropertynamedoesnot needtomatchthekeyoftheenvironmentproperty. InSpringBoot,relaxedbindingisapplicabletothetype-safebindingof theconfigurationproperties.
  • 123.
    Spring Boot Interview Questions www.edureka.co Question47 WhatdoyouunderstandbySpring Bootsupportsrelaxedbinding? Forexample,ifapropertyinabeanclasswiththe @ConfigurationProperties annotationisused sampleProp,thenitcanbeboundedtoanyofthefollowingenvironment properties: ❑sampleProp ❑sample_Prop ❑sample_Prop ❑SAMPLE_PROP
  • 124.
    Question 48 Spring Boot InterviewQuestions www.edureka.co Whereisthedatabaseconnection informationspecifiedandhowdoes itautomaticallyconnecttoH2?
  • 125.
    Spring Boot Interview Questions www.edureka.co Question48 Whereisthedatabaseconnection informationspecifiedandhowdoes itautomaticallyconnecttoH2? ItisbecauseoftheSpring Boot Autoconfiguration that,configuresthedependenciesoftheapplication. So,thedatabaseconnection information,andautomaticallyconnecting thedatabasetoH2isdonebytheauto-configurationproperty.
  • 126.
    Question 49 Spring Boot InterviewQuestions www.edureka.co WhatisthenameofthedefaultH2 databaseconfiguredbySpring Boot?
  • 127.
    Spring Boot Interview Questions www.edureka.co Question49 WhatisthenameofthedefaultH2 databaseconfiguredbySpring Boot? ThenameofthedefaultH2databaseistestdb spring.datasource.name=testdb # Name of the datasource. Note:Justin-caseifyouareusingH2in-memorydatabase,thenexactly thatisthenameofSpringBootwhichisusedtosetupyourH2database.
  • 128.
    Question 50 Spring Boot InterviewQuestions www.edureka.co Doyouthink,youcanusejetty insteadoftomcatinspring-boot- starter-web?
  • 129.
    Spring Boot Interview Questions www.edureka.co Question50 Yes,wecanusejettyinsteadoftomcatinspring-boot-starter-web,by removingtheexistingdependencyandincludingthefollowing: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter- jetty</artifactId> </dependency> Doyouthink,youcanusejetty insteadoftomcatinspring-boot- starter-web?
  • 130.