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
Q

What are the main elements of logback

A

appender & logger & root

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

State the attributed of appender

A

name, class > layout class > Pattern

27
Q

What is the general appender class

A

ch.qos.logback.core.ConsoleAppender

28
Q

What is the general class for layout class

A

ch.qos.logback.classic.PatternLayout

29
Q

What are the attributes of logger

A

name , level, additivity

30
Q

What is the subelement inside logger?

A

appender-ref ref=”STDOUT”

31
Q

WHat is the subelement for root

A

level , appender-ref ref=”STDOUT”

32
Q

What is the necessary annotations for an entity class?

A

@Entity , @Id

33
Q

If your Primary key is marked @Id, then what should be other annotation following?

A

@GeneratedValue(generator=”system-uuid”)

@genericGenerator(name=”system-uuid”, strategy=”uuid”)

34
Q

What are the advantage of Spring data?

A

The Spring data just needs to have the entity class and CRUD Repository, rest it will take care internally

35
Q

While extending the CrudRepository, what all it akes as generic parameters?

A

Class name & the primary key data type

36
Q

Can we autowired the constrtr also?

A

Yes

37
Q

Why we require to autowire contrtr

A

TBF

38
Q

What are the annotations required to make a class restEnabled?

A

Mark Class with @Controller Or @RestController
Mark class with @RequestMapping(“/”)
Mark the method with
@RequestMapping , Or @GetMapping Or @PostMapping

39
Q

What attributes are required inside the @RequestMapping

A

value, mehod , produces, consumes, header, name, params, path

40
Q

What should be the value of Value, Method & produces attribute of RequestMapping?

A

value=”/uri” method={RequestMethod.TYPE}, produces = All media type}

41
Q

What are the different MediaTypes?

A

MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE

42
Q

How can I return an Entity with RequestMapping?

A

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
Q

What are the one constrtr of ResponseEntity

A

new ResponseEntity>(this.repository.findAll(),headers, HttpStatus.OK);

44
Q

How can you return a view?

A

The return type should be a ModelAndView
Pass ModelAndView as an arg
and the return statement : modelandiew,setViewName(“index”)
return modelAndView

45
Q

How will you make the css files coming from a project folder?

A

by defining he path in annotation in servlet-context.xml < which is an DispatherServlet config xml>

46
Q

How will you make the css files coming from a project folder?

A

by defining the path in annotation in servlet-context.xml < which is an DispatherServlet config xml>

47
Q

Can you define the mvc:resources the attrbutes and value>

A
48
Q

By defauld which response will come to browser, if a services produces bit XML and JSON?

A

I think XML

49
Q

How will you get a specifically JSON response from a web service?

A

Specify header Accept: applicaion/json

50
Q

What are the javaconfig classes?

A

The annotated version classes for spring context xml and web xml

51
Q

How do we basically go with creating the configuration class?

A
Annotate the class with @Configuration
implement the class with WebMvcConfigurer
52
Q

How will you add the Trxn or other sort of capabilities to the cnfiguration class?

A

Generally every capability starts with Enable like :-
@EnableTransactionManagement
@EnableJpaRepositories(basePackages=””)
@EnableWebMvc

53
Q

What are the two WebMvcConfigurer methods to override?

A

addResourceHandlers(ResourceHandlersRegistry registry)
&
ConfireMessageConvertors(List>)

54
Q

So how will you implement the ResouceHandlers in Spring boot?

A
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
Q

How do you typically specify a path which belongs to classpath?

A

add prefix “classpath:”

56
Q

How will you configure MessageConvertors with javaconfig in Boot?

A
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
Q

How will you configure Resolver with javaconfig in Boot?

A

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
Q

How will you add the dataSource?

A

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
Q

How will you configure the entity manager factory?

A

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
Q

How will you configure the transactionManager()?

A

We can use below:-
@Bean
public PlatformTransactionManager transactionManager(){
JpaTransactionManager txManager = new JpatransactionManager();
txManager.setEntityMaagerFactory(entityManagerFactory()).
getNativeEntityManagerFactory();

return txManager;

}

61
Q

With Javconfig class in place do we still have to sme config in xml , if we are not using boot? (Spring 5)

A

Ues jsut add the in dispaterchaer xml

62
Q

Is there any alternative to javaconfig with xml context component scan way?

A

Yes You can use WebApplicationIntiallizer Class

63
Q

Say some advantage of Spring CLI on App?

A

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