PackageSerivce;import java.util.List; Import entity. Book; /** * Library Information business Logic Layer interface * @author Yin Tao * * */public interface bookserivce { /** * get all books Info * @return List of Books * /public list<book> getAll (); Public void Show ();
The Serivce code snippet above is basically consistent with the DAO layer code
The following code for SERIVCE implementation Class code is primarily used to test task scheduling
PackageSerivce.impl;ImportJava.util.List;ImportDao. Bookdao;ImportEntity. Book;ImportSerivce. Bookserivce;/*** Business Logic Layer Interface implementation class *@authorYin Tao **/PublicClass BookserivceimplImplementsBookserivce {Private BOOKDAO BD;//Data Access Layer ObjectsPublicvoidSETBD (Bookdao BD) {THIS.BD = BD;} @Override public list<book> getAll () {list<book> books=bd.getall (); System.out.println ("the title \ T Author"); for (book book:books) {System.out.println (Book.getname () + "\ T" +Book.getauthor ());} System.out.println ("\ n"); return Bd.getall ();} @Override public void Show () {System.out.println ("executes the specified time period code ...") ); Bd.show (); }}
Here is the main focus on configuring spring's Applicationcontext.xml file
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:p= "http://www.springframework.org/schema/p"Xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"><!--Defining DBCP Data sources-<BeanId= "DataSource"Class= "Org.apache.commons.dbcp.BasicDataSource"><!--Specifying the JDBC Driver class-<PropertyName= "Driverclassname"Value= "Oracle.jdbc.OracleDriver"></Property><!--Provide the URL address of the linked database-<PropertyName= "url"Value= "Jdbc:oracle:thin: @localhost: 1521:orcl"></Property><!--Provide the user name and password for the linked database-<PropertyName= "username"Value= "Scott"></Property><PropertyName= "Password"Value= "BDQN"></Property></Bean><!--Defining Sessionfactory Beans-<BeanId= "Sessionfactory"Class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!--Inject a well-defined data source for Localsessionfactorybean-<PropertyName= "DataSource"Ref= "DataSource"></Property><!--To add an object-relational mapping file-<PropertyName= "Mappingdirectorylocations"><List><!--The entity package under the SRC directory-<Value>classpath:entity</Value></List></Property></Bean><!--Inject DAO layer-<BeanId= "Bookdao"Class= "Dao.impl.BookDaoImpl"P:sessionfactory-ref= "Sessionfactory"></Bean><!--Injected into the SERIVCE layer-<BeanId= "Bookserivce"Class= "Serivce.impl.BookSerivceImpl"P:bd-ref= "Bookdao"></Bean><!--Configure the Task object The bean is executed at interval time-<BeanId= "Remindjob"Class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><!--Configure the class to invoke: The JavaBean object you want to use as the task class-<PropertyName= "TargetObject"Ref= "Bookserivce"></Property><!--Configure the method you want to invoke: The business method you want to use as a task method-<PropertyName= "Targetmethod"Value= "GetAll"></Property></Bean><!--Configure the Task object The bean executes for the specified time-<BeanId= "Remindjob2"Class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" > <!--Configure the class to invoke: The JavaBean object you want to use as the task class--<property name= "TargetObject" ref= "Bookserivce" ></property> <!--Configure the method to be called : The business method you want to use as a task method--<property name= "Targetmethod" value= "show" ></property> </bean> <!-- How long to configure trigger interval trigger--<bean id= "Mysimptrig" class= "Org.springframework.scheduling.quartz.SimpleTriggerBean" > <!--configuration Jobdetail ref-reference the Task object configured above--<property name= "Jobdetail" ref= "Remindjob" ></property> <!-- 1 seconds delay after configuration start 1000 milliseconds--<property name= "Startdelay" value= "></property>" <!--configuration repeat time interval is 5 seconds-- > <property name= "repeatinterval" value= "All" ></property> </bean> <!--the configuration trigger is executed for the specified time-- <bean id= "Mycrontrig" class= "Org.springframework.scheduling.quartz.CronTriggerBean" > <!--Injection Task class--< Property Name= "Jobdetail" ref= "Remindjob2" ></property> <!--Configure Cron expression order to second-dayThe month of the week is Monday to Monday Five Day 22 o'clock <property name= "cronexpression" value= "0 54 22? * 2-6 "></property> </bean> <!--configuration Scheduler--<bean class=" Org.springframework.scheduling.quartz.SchedulerFactoryBean "> <property name=" triggers "> <list> < !--Specify the trigger interval time period to execute--<ref bean= "Mysimptrig"/> <!--specified time--<ref bean= "Mycrontrig"/> </list > </property> </bean> </beans>
Spring Simple Task Scheduler