You are on page 1of 1

from this lecture we ae totally moving towards : removal of xml file.

==========================================================

two ways : xml based configuration , and java based configuration

for java based configuration : we can have @component annotation used on the class
for which we need the bean.

and in javaconfig document note : it should have .java extension :

@Configuration
@ComponentScan(basePackages = "com.springcore.javaconfig")
public class JavaConfig{}
-----------------------------------------------------------------------------------
-------

in main class
===========

ApplicationContext context = new


AnnotationConfigApplicationContext(JavaConfig.class);
rest same.

===============================================================================
changes we made on java.config file.

ie.we are annonating beea m


@bean
on method name
========================
@Configuration
public class JavaConfig{

@Bean(name = {"student","temp","con"})
public Student getStudent(){
Student student new Student(getSamosa());
return student;
}

we can get the bean using above these three bean name : ie. "student","temp","con".

==================================================================================

Three ways bean configuration


1. XML file
2.@component
3.java configuration use krke @Bean, spring container ko batlane k liye ki bhaiya
is class ka object manage krna hai.

baad me hmlog spring bean se object get kr skte hai.

You might also like