There are three places for DAO, service, and servlet
Generates an object by matching the file XML and injects properties of the object type, reducing the coupling
DAO file Code:
Package Com.swift; Public class Daouser { publicvoid Fun () { System.out.println ("I ' m Dao's Fun () ...................."); }}
Service File Code: (provides setter method, XML file can be configured in this way)
Package Com.swift; Public class serviceuser { private daouser DAO; Public void Setdao (Daouser dao) { this. dao = dao; } Public void Fun () { System.out.println ("I am Service's Fun () .....");; This . Dao.fun (); }}
XML File Code:
<?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://http://www.springframework.org/schema/beans/spring-beans.xsd"> classclass= "Com.swift.ServiceUser" ><property name= "Daouser" ref= "DAO" ></ Property></bean></beans>
The servlet class file can bypass the DAO file and use the service directly
Spring injects object type properties based on XML configuration file