Spring-Boot-101 Flashcards

1
Q

What is the default parent package

A

spring-boot-starter-parent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the default groupid for all the maven dependencies?

A

org.springframework.boot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is basically provided by the spring starter package

A

A server & a Main class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which starter package is for web app?

A

spring-boot-starter-web

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which archetype will generate webapp in maven?

A

maven-archetype-webapp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What dependency we require to add the JSON, Joda & XM Conversion capabilities?

A

We need to include jackson jar:
groupId : com.fasterxml.jackson.core
artifactId : jackson-databind

groupId : com.fasterxml.jackson.datatype
artifactId : jackson-datatype-joda

groupId : com.fasterxml.jackson.dataformat
artifactId : jackson-dataformal-xml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the default groupid for jackson ?

A

com.fasterxml.jackson.*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does does?

A

It scans all the classes that to be Autowired.

It includes @Service, @Configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does?

A

It tells that the app is a web app & thus scan and accentuate all the classes marked with @Controller Or @RestController & their methods @RequestMapping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What produces does in RequestMapping attribute types ?

A

It tells the Spring app what to do when their is a request with a specified header that is Accept : application/xml Or application/json, then respond accordingly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is jsonMapper and xmlMapper classes meant for?

A

This are the classes to help and format the data and create the right mapper

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What tag does?

A

This tag tells from where the jar files to be loaded, as generally pom.xml;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does?

A

This tag tells the spring data and spring container , the location of interface extended CRUDRepository

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does?

A

This tag has multiple usages, one of the usage that it tells from where the genesis scripts to be used and run

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

jpaVendorAdapter bean?

A

It tells the JPA implementor to be used, as Hibernate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is EntityManageFacory bean?

A

For all the JPA implementations , it is required to have a EntityManageFactory bean , as it creates the session and eexecute all the sql staments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is TransactionManager dean?

A

This will create helping transactions, this will be compliant with ACID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is ACID

A

Atomicity, Consistency, Isolation, Durability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does does?

A

This will help setting up the transactions in the app

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does viewResolverBean states?

A

It states the view the app will make use of , jsp or jsf…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does h2WebServer bean?

A

As H2 is an inmemory DB in Spring , this will quick do it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What do we require in persistence.xml?

A

We only require to have tag >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Does it require to declare the data classes in persistencexml?

A

No only persistence-unit name is required, rest will be taken care by Spring data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is logback.xml

A

It is for Loggers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are the main elements of logback
appender & logger & root
26
State the attributed of appender
name, class > layout class > Pattern
27
What is the general appender class
ch.qos.logback.core.ConsoleAppender
28
What is the general class for layout class
ch.qos.logback.classic.PatternLayout
29
What are the attributes of logger
name , level, additivity
30
What is the subelement inside logger?
appender-ref ref="STDOUT"
31
WHat is the subelement for root
level , appender-ref ref="STDOUT"
32
What is the necessary annotations for an entity class?
@Entity , @Id
33
If your Primary key is marked @Id, then what should be other annotation following?
@GeneratedValue(generator="system-uuid") | @genericGenerator(name="system-uuid", strategy="uuid")
34
What are the advantage of Spring data?
The Spring data just needs to have the entity class and CRUD Repository, rest it will take care internally
35
While extending the CrudRepository, what all it akes as generic parameters?
Class name & the primary key data type
36
Can we autowired the constrtr also?
Yes
37
Why we require to autowire contrtr
TBF
38
What are the annotations required to make a class restEnabled?
Mark Class with @Controller Or @RestController Mark class with @RequestMapping("/") Mark the method with @RequestMapping , Or @GetMapping Or @PostMapping
39
What attributes are required inside the @RequestMapping
value, mehod , produces, consumes, header, name, params, path
40
What should be the value of Value, Method & produces attribute of RequestMapping?
value="/uri" method={RequestMethod.TYPE}, produces = All media type}
41
What are the different MediaTypes?
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE
42
How can I return an Entity with RequestMapping?
It is really required that you have mapper and jackson view resolver configured, also the return type will ResponseEntity> and then you can return ResponseEnttitty bject
43
What are the one constrtr of ResponseEntity
new ResponseEntity>(this.repository.findAll(),headers, HttpStatus.OK);
44
How can you return a view?
The return type should be a ModelAndView Pass ModelAndView as an arg and the return statement : modelandiew,setViewName("index") return modelAndView
45
How will you make the css files coming from a project folder?
by defining he path in annotation in servlet-context.xml < which is an DispatherServlet config xml>
46
How will you make the css files coming from a project folder?
by defining the path in annotation in servlet-context.xml < which is an DispatherServlet config xml>
47
Can you define the mvc:resources the attrbutes and value>
48
By defauld which response will come to browser, if a services produces bit XML and JSON?
I think XML
49
How will you get a specifically JSON response from a web service?
Specify header Accept: applicaion/json
50
What are the javaconfig classes?
The annotated version classes for spring context xml and web xml
51
How do we basically go with creating the configuration class?
``` Annotate the class with @Configuration implement the class with WebMvcConfigurer ```
52
How will you add the Trxn or other sort of capabilities to the cnfiguration class?
Generally every capability starts with Enable like :- @EnableTransactionManagement @EnableJpaRepositories(basePackages="") @EnableWebMvc
53
What are the two WebMvcConfigurer methods to override?
addResourceHandlers(ResourceHandlersRegistry registry) & ConfireMessageConvertors(List>)
54
So how will you implement the ResouceHandlers in Spring boot?
``` Gnerally when we do not know the things to configure , we make use of Chain Of Responsibilty Pattern. Thus registry.addResourceHandler("/webjars/**"). addResourceLocattions("classpath:/META-INF/resources/webjars/", "/resources/", "/webjars/").resoucechain(true).addResolver(new WebJarsResourceResolver()) ```
55
How do you typically specify a path which belongs to classpath?
add prefix "classpath:"
56
How will you configure MessageConvertors with javaconfig in Boot?
``` You can use configueMessageConverters(List>) Jackson2ObjectMApperBuilder builder = new Jackson2ObjectMapperBuilder().builder.indentOutput(true).dateFormat(new SimplaDateFormat(""); convertors.add(new MappingJackson2HttpMessageConverter(builder.build()))); comvertors.add(new MappingJackson2XmlHtpMessageConverter(builder.createXmlMapper(true).buil;d()); ```
57
How will you configure Resolver with javaconfig in Boot?
We can use @Bean annotation and return InternalResourceViewResolver like below:- ``` @Bean public InternalResouceViewResolver jspViewResolver(){ InternalResouceViewResolver resolver = new InternalResoourceViewResolver(); ``` resolver. setPrefix("WEB-INF/views"); resolver. setrSuffix(".jsp") return resolver; }
58
How will you add the dataSource?
We will add Bean and return the DataSource:- in the java config Here you can also specify the scripts that needs t be run , when the app boots up
59
How will you configure the entity manager factory?
We can return LocalContainerEntityManagerFactoryBean like below:- @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory(){ ``` HibernAteJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); ``` vendorAdapter,showSql(true); LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory. setJpaVendorAdapter(vendorAdapter) factory. setDataSource(dataSource()); return factory;
60
How will you configure the transactionManager()?
We can use below:- @Bean public PlatformTransactionManager transactionManager(){ JpaTransactionManager txManager = new JpatransactionManager(); txManager.setEntityMaagerFactory(entityManagerFactory()). getNativeEntityManagerFactory(); return txManager; }
61
With Javconfig class in place do we still have to sme config in xml , if we are not using boot? (Spring 5)
Ues jsut add the in dispaterchaer xml
62
Is there any alternative to javaconfig with xml context component scan way?
Yes You can use WebApplicationIntiallizer Class
63
Say some advantage of Spring CLI on App?
The Spring CLI reads the annaotation and decides accordingly to run the app as WebApp, If @RestController andannotations like provided , it will try to run the app as webapp