0% found this document useful (0 votes)
13 views31 pages

38 Spring and Hibernet MCQ

The document provides a list of projects related to Spring Boot, React JS, and MySQL, along with YouTube links for each project. It also includes multiple-choice questions (MCQs) on Spring and Hibernate frameworks, along with their correct answers and explanations. Additionally, it promotes a premium subscription for access to more notes and materials.

Uploaded by

d.ankiit25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views31 pages

38 Spring and Hibernet MCQ

The document provides a list of projects related to Spring Boot, React JS, and MySQL, along with YouTube links for each project. It also includes multiple-choice questions (MCQs) on Spring and Hibernate frameworks, along with their correct answers and explanations. Additionally, it promotes a premium subscription for access to more notes and materials.

Uploaded by

d.ankiit25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Explore More

Subcription : Premium CDAC NOTES & MATERIAL @99

Contact to Join Click to Join


Premium Group Telegram Group

For More E-Notes


Join Our Community to stay Updated

TAP ON THE ICONS TO JOIN!


Project List

pg. 1 contact us on 8007592194 / 9284926333 www.codewitharrays.in


Project List

pg. 2 contact us on 8007592194 / 9284926333 www.codewitharrays.in


Project List

pg. 3 contact us on 8007592194 / 9284926333 www.codewitharrays.in


Project List

Spring Boot + React JS + MySQL Project List


Sr.No Project Name YouTube Link
1 Online E-Learning Hub Platform Project https://youtu.be/KMjyBaWmgzg?si=YckHuNzs7eC84-IW
2 PG Mate / Room sharing/Flat sharing https://youtu.be/4P9cIHg3wvk?si=4uEsi0962CG6Xodp
3 Tour and Travel System Project Version 1.0 https://youtu.be/-UHOBywHaP8?si=KHHfE_A0uv725f12
4 Marriage Hall Booking https://youtu.be/VXz0kZQi5to?si=llOS-QG3TpAFP5k7
5 Ecommerce Shopping project https://youtu.be/vJ_C6LkhrZ0?si=YhcBylSErvdn7paq
6 Bike Rental System Project https://youtu.be/FIzsAmIBCbk?si=7ujQTJqEgkQ8ju2H
7 Multi-Restaurant management system https://youtu.be/pvV-pM2Jf3s?si=PgvnT-yFc8ktrDxB
8 Hospital management system Project https://youtu.be/IynIouBZvY4?si=CXzQs3BsRkjKhZCw
9 Municipal Corporation system Project https://youtu.be/cVMx9NVyI4I?si=qX0oQt-GT-LR_5jF
10 Tour and Travel System Project version 2.0 https://youtu.be/_4u0mB9mHXE?si=gDiAhKBowi2gNUKZ

Sr.No
Project Name YouTube Link
11 Tour and Travel System Project version 3.0 https://youtu.be/Dm7nOdpasWg?si=P_Lh2gcOFhlyudug
12 Gym Management system Project https://youtu.be/J8_7Zrkg7ag?si=LcxV51ynfUB7OptX
13 Online Driving License system Project https://youtu.be/3yRzsMs8TLE?si=JRI_z4FDx4Gmt7fn
14 Online Flight Booking system Project https://youtu.be/m755rOwdk8U?si=HURvAY2VnizIyJlh
15 Employee management system project https://youtu.be/lD1iE3W_GRw?si=Y_jv1xV_BljhrD0H
16 Online student school or college portal https://youtu.be/4A25aEKfei0?si=RoVgZtxMk9TPdQvD
17 Online movie booking system project https://youtu.be/Lfjv_U74SC4?si=fiDvrhhrjb4KSlSm
18 Online Pizza Delivery system project https://youtu.be/Tp3izreZ458?si=8eWAOzA8SVdNwlyM
19 Online Crime Reporting system Project https://youtu.be/0UlzReSk9tQ?si=6vN0e70TVY1GOwPO
20 Online Children Adoption Project https://youtu.be/3T5HC2HKyT4?si=bntP78niYH802I7N
pg. 4 contact us on 8007592194 / 9284926333 www.codewitharrays.in
MCQ on Spring and Hibernate
Q1. Robert is working on a web application, where Spring is being used. He wants to apply
prototype scope in the bean named as ‘Person’. Which one of the following is the correct option
where the ‘Person’ bean works within the prototype scope :

(A) <bean id="person" class="com.test.Person" scope="Prototype"/>

(B) <bean id="person" class="com.test.Person" scope="prototype"/>

(C) <bean id="person" class="com.test.Person" PrototypeScope="true"/>

9 4
(D) <bean id="person" class="com.test.Person" Scope="prototype"/>

21
59
07
A1. B is correct. Option ‘A’ and ‘D’ has syntactical errors. Option ‘C’ has PrototypeScope which is not
80

a valid attribute. Hence B is correct.


.in

Q2. Spring framework offers us multiple ways to define the scope of a bean. Which one of the
ys

following is an incorrect way of defining a ‘request’ scope?


ra
ar
ith

(A) @RequestScope
w

public class Product {


de

// some properties & methods


co

(B) <bean id="product" class="com.test.Product" Scope="request"/>

(C) @Scope("request")
public class Product {
// some properties & methods
}

(D) <bean id="product" class="com.test.Product" scope="request"/>


A2. B is correct. Option B has incorrect attribute ‘Scope’. It should be ‘scope’. All Other options are
correct.

Q3. Select the option that is not a correct approach to create bean life cycle methods in Spring
framework?

(A) By using Annotations

(B) By implementing Interfaces provided by Spring framework

(C) By extending classes provided by Spring framework

4
(D) By using XML configuration

9
21
59
07
A3. C is correct. Spring doesn’t provide any class to extend in order to create life cycle methods, but
it provides interfaces.
80

Q4. Which interface out of the following options will you use to perform destruction of beans in the
.in

context of the spring life cycle methods?


ys
ra
ar

(A) InitializingBean
ith
w
de

(B) PostConstruct
co

(C) DisposableBean

(D) PreDestroy

A4. C is correct. Spring allows your bean to perform destroy callback method by implementing the
DisposableBean interface. Option B & D are the annotations, not the interface.

Q5. Who is capable of maintaining a registry of different beans and their dependencies in a Spring
based web application?
(A) BeanFactory class

(B) BeanFactory interface

(C) beanFactory method

(D) Client Application

A5. B is correct. A BeanFactory is the interface which is capable of maintaining a registry of different
beans and their dependencies.

9 4
21
Q6. Select the incorrect statement about BeanFactory in Spring Framework?

59
07
(A) BeanFactory holds bean definitions
80
.in

(B) BeanFactory instantiates beans whenever asked by the client application


ys
ra

(C) BeanFactory is capable of creating associations between dependent objects while


ar
ith
w

(D) BeanFactory supports the Annotation-based dependency Injection


de
co

A6. D is correct. BeanFactory does not support the Annotation-based dependency injection, whereas
ApplicationContext, a superset of BeanFactory does.

Q7. Four annotations given below, are used in Spring Boot based application. Which one is the
annotation of Spring Boot that is an alternative to Spring’s standard @Configuration annotation?

(A) @EnableAutoConfiguration

(B) @SpringBootConfiguration
(C) @ConfigurationProperties

(D) @ConfigurationPropertiesScan

A7. B is correct. @SpringBootConfiguration is an alternative to Spring’s standard @Configuration


annotation.

Q8. What is the purpose of @SpringBootConfiguration annotation in a Spring Boot web application?

(A) enables registration of extra beans in the context

9 4
21
(B) scans on the package where the application is located

59
07
(C) enables Spring Boot’s auto-configuration mechanism
80

(D) disables additional configuration classes from the application


.in
ys
ra
ar

A8. A is correct. @SpringBootConfiguration enables registration of extra beans in the context or the
ith

import of additional configuration classes.


w

Q9. Johnson is a developer. He is working in a Hibernate based application. He defines a class, called
de

‘InvoiceId’. The fields ‘category’ and ‘name’ will represent a unique InvoiceId as below:
co

@Embeddable
public class InvoiceId implements Serializable {

private String category;

private String name;


// getters and setters // equals() and hashCose()
}

Which of the following option represents that the ‘Invoice’ entity has a composite key?

(A) @Entity
public class Invoice {
@Id
@Embedded
private InvoiceId id;
private String description;

4
private Double amount;

9
21
//standard getters and setters
}

59
07
(B) @Entity
80

public class Invoice {


.in

@EmbeddedId
private InvoiceId id;
ys

private String description;


ra

private Double amount;


ar

//standard getters and setters


ith

}
w
de

(C) @Entity
co

public class Invoice {


@Id
private InvoiceId id;
private String description;
private Double amount;
//standard getters and setters
}

(D) @Entity
public class Invoice {
@EmbeddableId
private InvoiceId id;
private String description;
private Double amount;
//standard getters and setters
}

A9. B is correct. @EmbeddedId is the correct annotation to represent that an entity has a composite
key.

Q10. Suppose you are working on a Hibernate-based application. You have two classes as below.
You want to create a table into the database using hibernate ORM concept.

public class Employee {


private int id;

4
private Name name;

9
private double salary;

21
// getters & setters

59
}
07
public class Name {
80

private String firstName;


.in

private String lastName;


//getters & setters
ys

}
ra
ar
ith
w
de

You want to create a table named ’employee’ with 4 columns: Id, firstName, lastName, salary. Which
co

option is correct to create the aforesaid table. Assume that table & column names are not case-
sensitive.

(A) public class Employee {


@Id
private int id;
private Name name;
private double salary;
// getters & setters
}

@Embeddable
public class Name {
private String firstName;
private String lastName;
// getters & setters
}

(B) @Entity
public class Employee {
@Id
private int id;
@Embedded
private Name name;
private double salary;
// getters & setters
}

49
@Embedded

21
public class Name {

59
private String firstName;
private String lastName; 07
// getters & setters
80

}
.in
ys

(C) @Entity
ra

public class Employee {


@Id
ar

private int id;


ith

@Embedded
w

private Name name;


de

private double salary;


co

// getters & setters


}

@Entity
public class Name {
private String firstName;
private String lastName;
// getters & setters
}

(D) @Entity
public class Employee {
@Id
private int id;
@Embeddable
private Name name;
private double salary;
// getters & setters
}

@Entity
public class Name {
private String firstName;
private String lastName;
// getters & setters
}

9 4
A10. C is correct. In Option A , @Entity is missing in Employee class. In Option B, @Embedded is

21
disallowed at class level and In Option D, @Embeddable is disallowed at field level.

59
Q11. Mary is working in a Hibernate based application as a web-application developer. She has two
07
entities in her application: Student & Address. She is implementing a relation where One student can
80

have multiple addresses and one address can accommodate multiple students in a bidirectional
relationship. Mary doesn’t want hibernate to create one additional table. Which of the following
.in

annotation and its attribute will she use to fulfill the given requirement?
ys
ra
ar

(A) @ManyToMany and mappedBy


ith
w
de

(B) @ManyToOne and mappedBy


co

(C) @OneToMany and MappedBy

(D) @OneToOne and MappedBy

A11. C is correct. As per the problem statement, only @OneToMany or @MantToOne can be used.
Hence, Options A & D are incorrect. MappedBy attribute is disallowed in @ManyToOne, that makes
Option B also incorrect. Hence, option C is correct. If you wish to learn entity relationship concept in
detail, kindly visit a separate article on Entity Relationship In JPA/Hibernate/ORM.

Q12. In the context of Access types in Hibernate, if @Id is located at the getter method of an entity,
what does it mean?
(A) Entity access behavior is Field Access

(B) Entity access behavior is Property Access

(C) It represents both field & property access behavior

(D) From the given information, we can't determine the Access behavior

A12. B is correct. If we apply @Id on the getter method of an entity/class, it means property access
behavior is enabled. If we apply @Id on field, it means field access behavior is enabled.

9 4
21
Q13. Suppose you are working on a web application that uses Hibernate as an ORM tool. At which
level/(s) @Access is allowed to be used in an Entity?

59
07
80

(A) Field Level


.in
ys

(B) Method Level, Field Level


ra
ar

(C) Method Level


ith
w
de

(D) Field Level, Method Level, Class level


co

A13. D is correct. @Access can be used at all three levels : Field, Method & Class.

Q14. In JPA, which one of the following annotation converts the date and time values from Java
object to compatible database type and retrieves back to the application.

(A) @Timestamp

(B) @Time

(C) @Temporal
(D) @Date

A14. C is correct. @Temporal annotation converts the date and time values from Java object to
compatible database type and retrieves back to the application.

Q15. Jacob is working on a web application where JPA is being used in data layer. He wrote a POJO
class and wants this class to work as an entity to implement the ORM concept. What are the
minimum required annotations he must use at the class to create a table in the database?

(A) @Id, @Entity

9 4
21
(B) @Table, @Entity, @Id

59
07
(C) @Column, @Entity, @Table
80
.in

(D) @Id, @GeneratedValue


ys
ra
ar
ith

A15. A is correct. In order to create a table in the database, @Entity & @Id annotations are
mandatory, otherwise JPA will throw an exception.
w
de

Q16. Consider the following bean definition :


co

<bean id="test" class="com.dev.test.TestBean" />

Which of the below bean scope is applied in this bean?

(A) Session

(B) Request
(C) Prototype

(D) Singleton

A16. D is correct. A bean has singleton scope by default, whether we declare it in the bean definition
or not.

Q17. Robin is working in a Spring based web application. He declares the scope of a bean by using
annotations. Select the option which is incorrect in declaring the scope.

9 4
21
(A) @Component
@Scope("request")

59
public class Product { 07
//some methods and properties
80
}
.in

(B) @Component
ys

@Scope("session")
ra

public class Product {


ar

//some methods and properties


ith

}
w
de

(C) @Component
co

@Sessionscope
public class Product {
//some methods and properties
}

(D) @Component
@SessionScope
public class Product {
//some methods and properties
}
A17. C is correct. Option C has incorrect annotation. It should be ‘@SessionScope’ in place of
‘@Sessionscope’. All other options are correct.

Q18. Suppose you are working on a Spring based Web Application. Generally, there are three ways
to implement the core features of Spring framework in your application:

1) Using Annotation 2) Using XML configuration 3) Implementing Interfaces provided by Spring


framework

Which option is correct if you want to define Bean Lifecycle methods in your application:

(A) Only Option (1)

(B) Option (1) & Option (2)

9 4
21
(C) Option (2) & Option (3)

59
07
(D) All three
80
.in
ys

A18. D is correct. There are three ways to define bean life cycle methods: Annotation or XML
ra

configuration or Spring Interfaces.


ar

Q19. Which option is incorrect about @Component annotation?


ith
w
de
co

(A) It scans our application for classes annotated with @Component

(B) It instantiates classes whenever required

(C) It supports Spring's auto-detection mechanism

(D) It doesn't inject any specified dependencies

A19. D is correct. @Component annotation also injects any specified dependencies.


Q20. Melissa works in an application where Spring is being used. She wrote a custom function in a
class that handles bean life cycle disposal. By mistake, She also implemented the DisposableBean
interface and overrides the default method provided by the Spring container in the same class. What
will happen if she runs the application?

(A) Only default method will be called

(B) Only custom method will be called

(C) First default method and then custom method will be called

(D) First custom method and then default method will be called

9 4
21
59
A20. C is correct. Default methods provided by Spring always take precedence in a bean life cycle.
07
Q21. There are two classes ‘Product’ and ‘ProductCategory’ in a Spring based Project. You want to
80

inject ProductCategory into Product class by means of constructor injection. Which of the below
.in

option is correct to implement it?


ys
ra
ar

(A) @Component
ith

public class Product {


private int id;
w

@Autowired
de

private ProductCategory category;


co

public Product(ProductCategory category) {


this.category = category;
}
public ProductCategory getCategory() {
return category;
}
public void setCategory(ProductCategory category) {
this.category = category;
}
}

(B) @Component
public class Product {
private int id;
private ProductCategory category;
public Product(ProductCategory category) {
this.category = category;
}
public ProductCategory getCategory() {
return category;
}
@Autowired
public void setCategory(ProductCategory category) {
this.category = category;
}
}

(C) @Component
public class Product {

94
private int id;

21
private ProductCategory category;

59
@Autowired
public Product(ProductCategory category) {
07
this.category = category;
80

}
public ProductCategory getCategory() {
.in

return category;
ys

}
ra

public void setCategory(ProductCategory category) {


ar

this.category = category;
ith

}
w

}
de
co

(D) @Component
public class Product {
private int id;
private ProductCategory category;
public Product(ProductCategory category) {
this.category = category;
}
@Autowired
public ProductCategory getCategory() {
return category;
}
public void setCategory(ProductCategory category) {
this.category = category;
}
}

A21. C is correct. @Autowired annotation will be applied on constructor as the question is talking
about constructor injection.

Q22. Suppose you are working on a Student library system which is developed in the Spring
framework. There are four classes as shown below.

@Component
public class Student {

4
private int id;

9
private Address address;

21
}

59
@Component
public interface Address {
07
// some fields & Methods
80

}
.in

@Component
public class PermanentAddress implements Address {
ys

// some fields & Methods


ra

}
ar

@Component
ith

public class MailingAddress implements Address {


w

// some fields & Methods


de

}
co

You want to inject dependency of PermanentAddress class into Student class. Which option
represents the correct use of dependency injection?

(A) @Component
public class Student {
private int id;
@Autowired
private Address address;
}
(B) @Component
public class Student {
private int id;
@Autowired
@Qualifier("PermanentAddress")
private Address address;
}

(C) @Component
public class Student {
private int id;
@Autowired
@Qualifier
private Address address;
}

9 4
21
(D) @Component

59
public class Student { 07
private int id;
80
@Autowired
@Qualifier("permanentAddress")
.in

private Address address;


ys

}
ra
ar
ith
w

A22. D is correct. Spring container by default considers bean name same as the class name, but with
de

the first letter in lower case. In order to get more idea on @Qualifier, visit the article on @Qualifier
co

Annotation.

Q23. Which option is true for the role of BeanFactory in Spring Framework:

(A) BeanFactory provides the configuration framework and basic functionality

(B) BeanFactory provides access to messages in i18n-style

(C) BeanFactory provides access to resources, such as URLs and files


(D) BeanFactory provides event propagation to beans implementing the ApplicationLis

A23. A is correct. Options B, C, D are the roles of ApplicationContext, not the BeanFactory.

Q24. Select the option which is true about BeanFactory & ApplicationContext in the Spring
Framework:

(A) Any description of ApplicationContext capabilities and behavior should be consi

4
(B) An ApplicationContext is a complete superset of a BeanFactory

9
21
59
(C) BeanFactory builds on top of the ApplicationContext.
07
80

(D) When building most applications in a J2EE-environment, the best option is to us


.in
ys
ra
ar

A24. B is correct. According to Spring Framework documentation, option B is correct. For more
details, kindly refer the Spring Official Documentation.
ith
w

Q25. @SpringBootApplication annotation is a combination of three annotations. Which one of the


de

given option is not the part of a combination of three annotations?


co

(A) @SpringBootConfiguration

(B) @EnableAutoConfiguration

(C) @Configuration

(D) @ComponentScan
A25. A is correct. @SpringBootConfiguration is not the part of this combination, but the
@Configuration is. For more details, visit @SpringBootApplication annotation.

Q26. Consider the below code where the ‘Product’ entity has ‘Category’ as @EmbeddedId and other
fields related to a product. A ‘Category’ tells Hibernate that the ‘Product’ entity has a composite key.

@Entity
public class Product implements Serializable {
@EmbeddedId
private Category id;
private String name;
//getters & setters
}

9 4
21
What will be the structure of the Person entity in the context of the above composite key?

59
07
80

(A) @Embedded
public class Category implements Serializable {
.in

private String name;


ys

private String description;


ra

//getters & setters


ar

}
ith
w

(B) @Component
de

public class Category implements Serializable {


co

private String name;


private String description;
//getters & setters
}

(C) @Entity
public class Category implements Serializable {
private String name;
private String description;
//getters & setters
}

(D) @Embeddable
public class Category implements Serializable {
private String name;
private String description;
//getters & setters
}

A26. D is correct. We represent a composite primary key in Hibernate by using the @Embeddable
annotation on a class.

Q27. In a Hibernate based application, in order to interact with the database, we make use of various
methods provided by EntityManager API. Which statement is false in the context of these methods?

9 4
(A) We can make use of the persist() method in order to have an object associated w

21
59
(B) We can use the findReference() method, if we just need the reference to the ent
07
80

(C) We can use the detach() method to detach an entity from the persistence context
.in
ys

(D) We can use the find() method to retrieve an object from the database.
ra
ar
ith
w
de

A27. B is correct. If we just need the reference to the entity, we can use the getReference() method,
not the findReference().
co

Q28. In order to access entity attributes, we implement access strategies in Hibernate. Which type/(s)
of Access strategy/(ies) is allowed in Hibernate?

(A) field-based access

(B) property-based access

(C) class-based access


(D) field-based access & property-based access

A28. D is correct. There are two types of access strategies allowed in Hibernate : field-based access
and property-based access.

Q29. Sophia is using Spring Data JPA for the data layer implementations in her web application. She
wrote a custom method in the repository. She is using ‘update’ query to implement the functionality
of the method. Which one of the following annotation she should use on that method?

(A) @Updating

9 4
21
(B) @Updated

59
07
(C) @Modifying
80
.in

(D) @Modified
ys
ra
ar
ith

A29. C is correct. Only @Modifying annotation is available. All others are incorrect.
w

Q30. Which option is incorrect about Spring Framework?


de
co

(A) It is a lightweight framework.

(B) Spring applications are loosely coupled because of dependency injection.

(C) It offers only Java-based annotations for configuration options.

(D) It provides declarative support for caching, validation, transaction, and forma
A30. C is correct. Apart from Java-based annotations, it also offers XML based configuration
options. Hence option ‘C’ is the right answer.

Q31. What is the main component of the Spring framework?

(A) Servlet API

(B) Hibernate ORM

(C) Spring Core Container

(D) Spring Data JPA

9 4
21
59
A31. C is correct. The Spring Core Container is the main component of the Spring framework, which
07
is responsible for managing the application’s beans and their dependencies.
80

Q32. What is the purpose of the BeanFactory interface in Spring?


.in
ys
ra

(A) To manage the lifecycle of beans


ar
ith

(B) To provide a simple way to retrieve bean instances


w
de

(C) To define beans and their dependencies


co

(D) To handle transaction management

A32. B is correct. The BeanFactory in Spring is an interface that provides a simple way to retrieve
bean instances.

Q33. What is the main difference between ApplicationContext and BeanFactory in Spring?

(A) BeanFactory is a sub-interface of ApplicationContext


(B) ApplicationContext provides additional functionalities than BeanFactory

(C) BeanFactory and ApplicationContext both are same

(D) ApplicationContext and BeanFactory are interchangeable

A33. B is correct. The ApplicationContext interface in Spring is a sub-interface of BeanFactory and


provides additional functionalities like event publishing, internationalization, and application-level
contexts.

Q34. What is the purpose of the @Autowired annotation in Spring?

9 4
21
(A) To define a bean in the Spring application context

59
07
(B) To inject dependencies into a bean
80
.in

(C) To define the scope of a bean


ys
ra

(D) To define the lifecycle of a bean


ar
ith
w
de

A34. B is correct. The @Autowired annotation in Spring is used to inject dependencies into a bean,
co

either through constructor injection, setter injection, or field injection.

Q35. What is Inversion of Control in Spring?

(A) A design pattern that allows for greater control over an application's objects

(B) A technique for delegating control of the application to a central authority

(C) A method for controlling an application's flow of control from the inside out
(D) The term 'Inversion of Control' is not used in Spring

A35. B is correct. Inversion of Control (IoC) is a technique for delegating control of the application to
a central authority, such as the Spring IoC container. The container creates and manages the objects
and their dependencies, allowing the objects to focus on their specific responsibilities.

Q36. Which of the following caching strategies in Hibernate stores data in a cache that can be
accessible across different sessions?

(A) Query cache

9 4
21
(B) First-level cache

59
07
(C) Second-level cache
80
.in

(D) Collection cache


ys
ra
ar
ith

A36. C is correct. The first-level cache is related to a single session and is used to cache data within
that session only. The second-level cache in Hibernate caches data across different sessions. It stores
w
de

the cached data in a shared cache region. It allows multiple sessions to access the same data without
hitting the database. The query cache caches the results of queries, and the collection cache caches
co

the persistent collections.

Q37. You are working in a Spring Boot application that needs to connect to a relational database.
You want to configure the data source properties, such as URL, username, and password, in the
application.properties file. Which of the following is the correct way to configure the data source
properties in the application.properties file for an H2 in-memory database?

(A)
jdbc.url=jdbc:h2:mem:testdb
jdbc.username=admin
jdbc.password=admin123

(B)
db.datasource.url=jdbc:h2:mem:testdb
db.datasource.username=admin
db.datasource.password=admin123

(C)
spring.db.datasource.url=jdbc:h2:mem:testdb
spring.db.datasource.username=admin
spring.db.datasource.password=admin123

(D)
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=admin
spring.datasource.password=admin123

9 4
21
59
A37. D is correct . In a Spring Boot application, you typically configure data source properties in the
07
application.properties or application.yml file. Spring Boot uses the spring.datasource prefix to
identify data source-related properties.
80

Q38. In a spring application there are four classes some code segments are defined in the given
.in

options select the one which would contain the business logic.
ys
ra
ar

(A)
ith

public class ProductController {


w

@PostMapping("/product")
de

public Product createProduct(@RequestBody Product product) {


co

return productService.saveProduct(product);
}
}

(B)
public class ProductService {
public Product saveProduct(Product product) {
if (product.getPrice() > 0) {
return productRepository.save(product);
} else {
throw new IllegalArgumentException("Price must be greater than zero");
}
}
}
(C)
public interface ProductRepository extends JpaRepository<Product, Long> {
// Data access methods
}

(D)
public class ProductValidator {
public boolean isValid(Product product) {
// Validation logic
return product.getPrice() > 0;
}
}

9 4
21
59
A38. B is correct. The class ProductService, as shown in option B, is the most appropriate place for
07
business logic in a Spring application. In this case, ProductService handles the core logic for
validating and saving a product. The ProductController class in option A is responsible for handling
80

incoming HTTP requests, while the ProductRepository interface in option C manages data
.in

persistence. The ProductValidator class in option D might be used for specific validation or utility
functions but does not typically contain business logic.
ys
ra
ar
ith
w
de
co
https://www.youtube.com/@codewitharrays

https://www.instagram.com/codewitharrays/

https://t.me/codewitharrays Group Link: https://t.me/ccee2025notes

+91 8007592194 +91 9284926333

[email protected]

https://codewitharrays.in/project

You might also like