First You create Config Class for Configuration like this
package com.example.amer.config;
import com.example.amer.dao.MyDaoImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Config {
@Bean(name = "myDaoImpl")
public MyDaoImpl myDaoImpl()
{
MyDaoImpl myDao = new MyDaoImpl();
return myDao;
}
}
here we create MyDaoImpl Bean
and MyDao interface
package com.example.amer.dao;
public interface MyDao {
public String getUserByName();
}
and the Driver class
package com.example.amer;
import com.example.amer.dao.MyDao;
public class Driver {
MyDao myDao;
public MyDao getMyDao() {
return myDao;
}
public void setMyDao(MyDao myDao) {
this.myDao = myDao;
}
}
next i will create the xml beans like this
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Scan the JavaConfig -->
<context:component-scan base-package="com.example.amer.config" />
<bean id="driver" class="com.example.amer.Driver">
<property name="myDao" ref="myDaoImpl"></property>
</bean>
</beans>
here in xml we scan about Java Configuration that contains MyDao Impl
the i create the Driver bean and define to myDao Property then i refer to MyDaoImpl bean with it's name defined in @Bean(name="myDaoImpl")
so it will work.