推荐先阅读
:Spring全家桶
public interface BookDao {} public class BookDaoImpl implements BookDao {} public interface BookService {} public class BookServiceImpl implements BookService {}
|
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="bookDao" class="com.zx.dao.impl.BookDaoImpl"/> <bean id="bookService" class="com.zx.service.impl.BookServiceImpl"/> </beans>
|
public class App { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); BookDao bookDao = (BookDao) ctx.getBean("bookDao"); BookService bookService = (BookService) ctx.getBean("bookService"); } }
|