0% found this document useful (0 votes)
2 views3 pages

Exercise 1 - Configuring A Basic Spring Application

Uploaded by

bharathwaj0712
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)
2 views3 pages

Exercise 1 - Configuring A Basic Spring Application

Uploaded by

bharathwaj0712
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

Exercise 1: Configuring a Basic Spring Application

Scenario:

Your company is developing a web application for managing a library. You need to use the Spring Framework to
handle the backend operations.

SOLUTION:

Step 1) Set Up a Spring Project

[Link]:

<project xmlns="[Link] xmlns:xsi="[Link]


instance" xsi:schemaLocation="[Link]
[Link]
<modelVersion>4.0.0</modelVersion>
<groupId>[Link]</groupId>
<artifactId>LibraryManagement</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-context</artifactId>
<version>6.1.8</version>
</dependency>
</dependencies>
</project>

Step 2) Configure the Application Context

[Link]:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="
[Link]
[Link]

<bean id="bookRepository"
class="[Link]"/>

<bean id="bookService"
class="[Link]">
<property name="bookRepository"
ref="bookRepository"/>

</bean>

</beans>

Step 3) Define Service and Repository Classes

[Link]:
package [Link];

public class BookRepository {

public void displayRepository() {


[Link]("BookRepository Bean Created");
}
}

[Link]:
package [Link];

import [Link];

public class BookService {

private BookRepository bookRepository;

public void setBookRepository(BookRepository bookRepository) {


[Link] = bookRepository;
}

public void displayService() {


[Link]("BookService Bean Created");
[Link]();
}
}

[Link]:
package [Link];

import [Link];
import [Link];

import [Link];

public class MainApp {

public static void main(String[] args) {

ApplicationContext context =
new ClassPathXmlApplicationContext("[Link]");

BookService service =
(BookService) [Link]("bookService");

[Link]();
}
}
Step 4) Output

You might also like