0% found this document useful (0 votes)
3 views1 page

Spring Notes

The document provides notes on creating a Spring project with Maven, including setting up the Spring context and IOC container. It explains the differences between BeanFactory and ApplicationContext, as well as XML configuration for beans, and details on setter and constructor injection. Additionally, it covers autowiring and resolving ambiguity with primary beans.
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)
3 views1 page

Spring Notes

The document provides notes on creating a Spring project with Maven, including setting up the Spring context and IOC container. It explains the differences between BeanFactory and ApplicationContext, as well as XML configuration for beans, and details on setter and constructor injection. Additionally, it covers autowiring and resolving ambiguity with primary beans.
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/ 1

Spring and Spring Boot Notes

1. Creating Spring Project with Maven

- Use Spring Boot starter Maven archetype

- Add Spring context dependency in pom.xml

2. Creating IOC Container

- Use ApplicationContext interface

ApplicationContext context =
new ClassPathXmlApplicationContext("spring.xml");

- To get managed class object:

context.getBean(Dev.class);

3. BeanFactory vs ApplicationContext

- BeanFactory is basic; ApplicationContext is advanced and pre-loads beans.

4. XML Configuration for Beans


<bean id="dev" class="com.package.Dev">
<property name="age" value="12"/>
</bean>

5. Setter Injection

- Uses <property> tag in XML

6. Constructor Injection
<bean>
<constructor-arg index="0" value="16"/>
</bean>
public Dev(int age) {
this.age = age;
}

7. Autowire and Primary

- Use autowire="byType"

- Use primary="true" to resolve ambiguity

You might also like