??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品乱码久久久久久黑人,wwwww在线观看免费视频,色爱av综合网 http://www.aygfsteel.com/laoding/category/34397.html本来我以为,隐n了别人就找不到我Q没有用的,像我q样拉风的男人,无论走到哪里Q都像在黑暗中的萤火虫一P那样的鲜明,那样的出众。我那忧郁的眼神Q稀疏的胡茬Q那微微隆v的将军肚和亲切的W容......都深深吸引了众h...... zh-cn Wed, 26 Nov 2008 15:36:30 GMT Wed, 26 Nov 2008 15:36:30 GMT 60 spring aop单日志实?2) http://www.aygfsteel.com/laoding/articles/242613.html老丁 老丁 Tue, 25 Nov 2008 10:27:00 GMT http://www.aygfsteel.com/laoding/articles/242613.html http://www.aygfsteel.com/laoding/comments/242613.html http://www.aygfsteel.com/laoding/articles/242613.html#Feedback 0 http://www.aygfsteel.com/laoding/comments/commentRss/242613.html http://www.aygfsteel.com/laoding/services/trackbacks/242613.html (注意是spring2.0)
来看接口Q这个接口简单的不能再简单了Q嘻嘅R?br />
public interface Hello {
String hello(String name);
}
实现c:
public class SayHello implements Hello {
public String hello(String name) {
String result = " ---hello " + name;
System.out.println(result);
return result;
}
}
切面Q里面采用了annotation来注释,也说明了大概意思:
/*
* Create Date:2008-11-20 下午03:09:11
*
* Author:dingkm
*
* Version: V1.0
*
* DescriptionQ对q行修改的功能进行描q?nbsp;
*
*
*/
// 首先q是注释q个cd是切?/span>
@Aspect
public class MyAspect {
// q里是注释要切入的方法,AfterReturning是表C方法返回以后进行切入,我这?br />
// 选这个的话是因ؓ日志一般都是在Ҏ执行完成后记录,当然你可以拿Before来试
@AfterReturning( " execution(* *.aspectJ.*.hello(..)) " )
public void doLog(ProceedingJoinPoint joinpoint) throws Throwable{
String result = (String)joinpoint.proceed();
System.out.println( " ---doLog " + result);
}
}
下面是spring配置文gQ这里的配置文g比较简单了Q?br />
<? xml version="1.0" encoding="UTF-8" ?>
< beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd" >
<!-- Z@AspectJ切面的驱动器Q如果没有这句话 切面的代码是不会执行的,可以试下 -->
< aop:aspectj-autoproxy />
<!-- q个bean是作为切?nbsp; -->
< bean id ="myAspect" class ="spring2aop.aspectJ.MyAspect" ></ bean >
<!-- 要织入代码的bean -->
< bean id ="hello" class ="spring2aop.aspectJ.SayHello" ></ bean >
</ beans >
<aop:aspectj-autoproxy/>q句很关键哦
再来看测试类Q?br />
public class Test {
/**
* @Description Ҏ实现功能描述
* @param args
* void
* @throws 抛出异常说明
*/
public static void main(String[] args) {
ApplicationContext act = new ClassPathXmlApplicationContext(
" applicationContext21.xml " );
Hello h = (Hello)act.getBean( " hello " );
h.hello( " laoding " );
}
}
看看l果Q?br />
---hello laoding
---hello laoding
---doLog---hello laoding
---hello laoding q个与上一文章中提到的道理一P因ؓ记录日志要取得返回结果,所以执行了两次
最后的那句是我们要的Q这样就辑ֈ了记录日志的目的Q哈哈,收工回去看PPS中韩兽Ҏ?/span>
]]> spring aop单日志实?1) http://www.aygfsteel.com/laoding/articles/242611.html老丁 老丁 Tue, 25 Nov 2008 10:14:00 GMT http://www.aygfsteel.com/laoding/articles/242611.html http://www.aygfsteel.com/laoding/comments/242611.html http://www.aygfsteel.com/laoding/articles/242611.html#Feedback 0 http://www.aygfsteel.com/laoding/comments/commentRss/242611.html http://www.aygfsteel.com/laoding/services/trackbacks/242611.html 一直就用spring的IOCQ遗憾spring的另一重要l成部分AOP却没用过Q所以近几天抽空研究了下AOPQ学了些东西Q在q里记录?span style="color: red">spring2.0的aop配置Q以一个简单的记录日志的实例来说明Q先介绍下用XMLSchema来配|,下一介lannotation配置Q废话不多说Q开始吧
先新Zweb工程Q将spring的包加进去,为方便就把全部的jar包加q去?br />
先来看个接口Q很单就两个Ҏ
public interface Print {
public String print(String name);
public String sleep(String name);
}
接下来是实现c?br />
public class SystemPrint implements Print{
public String print(String name){
String result = " hello " + name;
System.out.println(result);
return result;
}
public String sleep(String name){
String result = name + " is sleep now " ;
System.out.println(result);
return result;
}
}
下面是所要织入的代码Q也是我们要用来记录日志的
public class GetLog {
public void getLog(ProceedingJoinPoint joinpoint) throws Throwable {
String reslut = (String)joinpoint.proceed();
// q里是记录日志的
System.out.println( " result=== " + reslut);
}
}
再来看spring配置文gQ没有注释的很清楚,可以ȝ上查?br />
<? xml version="1.0" encoding="UTF-8" ?>
< beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd" >
<!-- q个bean是作为切?nbsp; -->
< bean id ="log" class ="spring2aop.GetLog" ></ bean >
<!--
注意q里Qexpression="execution(* spring2aop.*.print*(..))"
括号里面W一?号代表返回?nbsp;接下?nbsp; spring2aop.*. 是你要切入的代码的大概\径,q里Z么用大概路径来Ş容呢
因ؓq里的意思是W合以spring2aop的\径都会作为选择的对象,也不详细介绍Q查下就明白了, print*(..)是指
Ҏ名以print开头的都符合,括号里面?nbsp;.. 表示参数是随意的都可以?br />
-->
< aop:config >
< aop:aspect ref ="log" >
< aop:pointcut id ="printMethods" expression ="execution(* spring2aop.*.print*(..))" />
< aop:after-returning method ="getLog" pointcut-ref ="printMethods" returning ="retVal" />
</ aop:aspect >
</ aop:config >
< aop:config >
< aop:aspect ref ="log" >
< aop:pointcut id ="sleepMethods" expression ="execution(* spring2aop.*.sle*(..))" />
< aop:after-returning method ="getLog" pointcut-ref ="sleepMethods" returning ="retVal" />
</ aop:aspect >
</ aop:config >
<!-- 要织入代码的bean -->
< bean id ="print" class ="spring2aop.SystemPrint" ></ bean >
</ beans >
试c:
public class Test {
/**
* @Description Ҏ实现功能描述
* @param args
* void
* @throws 抛出异常说明
*/
public static void main(String[] args) {
ApplicationContext act = new ClassPathXmlApplicationContext(
" applicationContext20.xml " );
Print t = (Print)act.getBean( " print " );
t.print( " ding " );
System.out.println( " ----------------- " );
t.sleep( " laoding " );
}
}
q行q个c,得到如下l果Q?br />
hello ding
hello ding
result===hello ding
-----------------
laoding is sleep now
laoding is sleep now
result===laoding is sleep now
q里的hello ding 打印了两ơ,不用担心Q这是因为执行到getLog切面cȝ
String reslut = (String)joinpoint.proceed();q句代码的时候再执行了一ơ,q句代码是取?br />
q回l果的,可以讄个断Ҏ试下好了这里就输出的result是记录的日志,当然
q里只是个很单的实现Q但是很单的实现却很Ҏ说清楚原理?img alt="" src="/CuteSoft_Client/CuteEditor/images/emsmile.gif" align="absMiddle" border="0" />
]]>spring常见错误分析 http://www.aygfsteel.com/laoding/articles/238018.html老丁 老丁 Sat, 01 Nov 2008 05:12:00 GMT http://www.aygfsteel.com/laoding/articles/238018.html http://www.aygfsteel.com/laoding/comments/238018.html http://www.aygfsteel.com/laoding/articles/238018.html#Feedback 0 http://www.aygfsteel.com/laoding/comments/commentRss/238018.html http://www.aygfsteel.com/laoding/services/trackbacks/238018.html
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''org.springframework.aop.support.DefaultPointcutAdvisor'' defined in null: Can''t resolve reference to bean ''txAdvice'' while setting property ''advice''; nested exception is
原因Q缺Spring开头的各种包,到Spring2.0 src中编译新的dist目录出来Q拷贝全部的springxxx.jar到jpetstore/WEB-INF/lib下。OK?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
现象2Q?br />
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sessionFactory'' defined in resource [/WEB-INF/dataAccessContext-hibernate.xml] of ServletContext: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
原因Q缺jta.jarQOK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
现象3Q?br />
java.lang.NoClassDefFoundError: org/dom4j/Attribute~dom4j.jar
java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
~ehcache.jar
java.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory
~cglib-full.jar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
现象4Q?br />
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''sessionFactory'' defined in resource [/WEB-INF/dataAccessContext-hibernate.xml] of ServletContext: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: could not instantiate id generator
net.sf.hibernate.MappingException: could not instantiate id generator
原因Q?br />
hbm中id字段的定义ؓ没有定义的sequesce,修改为inc
name="id"
type="string"
column="userid"
>
// 原来是sequence.
q样可以了?br />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
现象6Q?br />
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''/shop/addItemToCart.do'' defined in ServletContext resource [/WEB-INF/petstore-servlet.xml]: Can''t resolve reference to bean ''petStore'' while setting property ''petStore''; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ''petStore'' is defined
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ''petStore'' is defined原因Q?br />
我用Struts作ؓaction,当然׃需要用Spring WEB framework,因此也不需要与之配套的配置文g例如,petstore-servlet.xml,
q有remote-servlet.xml ,但是Spring仍旧加蝲此两个文Ӟ没办法,只好此两个文g挪动到别的地方,但是又出现找不到q两?br />
文g的IO异常Q没办法Q只好又拯回来Q然后把文g内容晴空?br />
l于好用了?br />
原因是Q只要你在web.xml中定义了q个servletQ他pL此servlet名字对应的配|文Ӟservletname-servlet.xmlQ?找不到就出错。okQ现在注释掉web.xml中名字ؓpetstore的servlet定义和媄Ԍ删除petstore-servlet.xml文gQ哈哈,q下不报告错误了?br />
同理Q注释名字ؓremote的servletQ删除remote-servlet.xml后,重新启动tomcatQ这下不报告M错误了。呵c原来如此啊?br />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
现象Q?br />
java.lang.NullPointerException
srx.test.testhibernate.UserDAO.getAll(UserDAO.java:9)
srx.test.struts.action.UserAction.execute(UserAction.java:20)原因Q?br />
Action原来
UserDAO // q个cOK
public class UserDAO extends HibernateDaoSupport {
public List getAll() {
return this.getHibernateTemplate().find("select aa from Account aa");
}
}
//q个c需要修?br />
public class UserAction extends ActionSupport {
UserDAO dao = new UserDAO();
List accounts = dao.getAll();
。。?br />
}
修改Q?br />
//UserDAO dao = new UserDAO(); WebApplicationContext wac = this.getWebApplicationContext();
UserDAO dao = (UserDAO) wac.getBean("userDAO");
本文转自Qhttp://main.blog.hexun.com/14227514_d.html
]]> Spring自动装配(autowire)协作?/title> http://www.aygfsteel.com/laoding/articles/237285.html老丁 老丁 Wed, 29 Oct 2008 01:44:00 GMT http://www.aygfsteel.com/laoding/articles/237285.html http://www.aygfsteel.com/laoding/comments/237285.html http://www.aygfsteel.com/laoding/articles/237285.html#Feedback 0 http://www.aygfsteel.com/laoding/comments/commentRss/237285.html http://www.aygfsteel.com/laoding/services/trackbacks/237285.html
模式 说明
no 不用自动装配,必须通过ref元素指定依赖Q默认设|?nbsp;
byName Ҏ属性名自动装配。此选项检查容器ƈҎ名字查找?nbsp;
属性完全一致的beanQƈ其与属性自动装配?nbsp;
byType 如果容器中存在一个与指定属性类型相同的beanQ那么将?nbsp;
该属性自动装配;如果存在多个该类型beanQ那么抛出异
常,q指Z能用byType方式q行自动装配Q如果没有找
到相匚w的beanQ则什么事都不发生Q也可以通过讄
dependency - check = " objects " 让Spring抛出异常?nbsp;
constructor 与byType方式cMQ不同之处在于它应用于构造器参数。如
果容器中没有扑ֈ与构造器参数cd一致的beanQ那么抛?nbsp;
异常?nbsp;
autodetect 通过beancȝ自省机制QintrospectionQ来军_是?nbsp;
constructorq是byType方式q行自动装配。如果发现默认的
构造器Q那么将使用byType方式?/span>
可以讄bean使自动装配失效:
采用xml格式配置beanӞ?lt;bean/>元素的autowire-candidate属性设|ؓfalseQ这样容器在查找自动装配对象Ӟ不考虑该beanQ即它不会被考虑作ؓ其它bean自动装配的候选者,但是该bean本nq是可以使用自动装配来注入其它bean的?br />
下面用实例来说明Q准?个类
public class Home {
private String addr;
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this .addr = addr;
}
}
public class Person {
private String name;
private Home myHome;
public Person(Home myHome){
this .myHome = myHome;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
public Home getMyHome() {
return myHome;
}
public void setMyHome(Home myHome) {
this .myHome = myHome;
}
}
public class Test {
private Date time;
private String str;
public Date getTime() {
return time;
}
public void setTime(Date time) {
this .time = time;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this .str = str;
}
}
一.byName的装配方?br />
spring配置文g
<? 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-2.0.xsd" >
< bean id ="test" class ="autowire.Test" autowire ="byName" >
< property name ="str" >
< value > ding </ value >
</ property >
</ bean >
< bean id ="time" class ="java.util.Date" />
</ beans >
试c:
public class TestMain {
public static void main(String[] args) {
ApplicationContext at = new ClassPathXmlApplicationContext( " applicationContext9.xml " );
Test t = (Test)at.getBean( " test " );
/*
代码若采用了byName的装配方式,也就是在配置文g中id为test的bean装入后,因ؓ是byName装配Q同?br />
TestcM含有time属性,所以spring会自动查找id为time的bean来设|time的倹{?br />
若在配置文g中把autowire="byName"LQ则time的gؓI?br />
*/
System.out.println(t.getStr());
System.out.println(t.getTime());
}
执行q个cd以看刎ͼ
ding
Wed Oct 29 09:19:29 CST 2008
证明time已经被注入了
若在配置文g中把autowire="byName"LQ则可以看到
ding
null
?byName的装配方?br />
代码都不用改Q只需要在spring配置文g里面?autowire="byName"换成autowire="byType"可以了
q种装配方式Q则spring会自动查找与TestcMtime属性类型相同的beanQ不这?br />
bean的id是什么(byName中的id必须与属性对应,而这里不要求Q,都可以用来设|time的|随便改动
bean的名字都可以Q比?lt;bean id="ti252752" class="java.util.Date"/>的名字都可以Q同h对的
若存在多个这LbeanQ则会抛出异常?br />
增加一个bean <bean id="time2" class="java.util.Date"/>
q行可以看到异常Q?br />
Exception in thread " main " org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name ' test ' defined in class path resource [applicationContext9.xml]:
Unsatisfied dependency expressed through bean property ' time ' : There are 2 beans of type [java.util.Date]
available for autowiring by type: [ti252752, time2]. There should have been exactly 1 to be able to autowire
property ' time ' of bean ' test ' . Consider using autowiring by name instead.
?构造方法装?br />
spring配置文g
<? 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-2.0.xsd" >
< bean id ="person" class ="autowire.Person" autowire ="constructor" >
< property name ="name" >
< value > ding </ value >
</ property >
</ bean >
< bean id ="myHome" class ="autowire.Home" >
< property name ="addr" >
< value > 江西 </ value >
</ property >
</ bean >
</ beans >
试c?br />
public class TestMain2 {
public static void main(String[] args) {
ApplicationContext atx = new ClassPathXmlApplicationContext( " applicationContext10.xml " );
Person p = (Person)atx.getBean( " person " );
System.out.println(p.getName());
System.out.println(p.getMyHome().getAddr());
/*
* q段代码是通过构造方法装载的Q配|文仉面有autowire="constructor"QPersonc里?br />
* 的构造方法含有参数myHomeQspring会通过q个构造方法来查找与构造方法参数类型相同的beanQ?br />
* 把它装蝲q来Q如果出C个类型一Lbean会抛出异常?br />
* */
}
}
若将Personc里?nbsp;含有参数myHome的构造方法去掉则会报?br />
?不用自动装?br />
<? 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-2.0.xsd " >
< bean id = " person " class = " autowire.Person " >
< property name = " name " >
< value > ding </ value >
</ property >
< property name = " myHome " >
< ref local = " myHome " />
</ property >
</ bean >
< bean id = " myHome " class = " autowire.Home " >
< property name = " addr " >
< value > 江西 </ value >
</ property >
</ bean >
</ beans >
public class TestMian3 {
public static void main(String[] args) throws Exception {
// 默认的no装蝲模式
ApplicationContext atx = new ClassPathXmlApplicationContext(
" applicationContext11.xml " );
Person p = (Person) atx.getBean( " person " );
System.out.println(p.getName());
System.out.println(p.getMyHome().getAddr());
// 若用这个Personcȝ构造方法需是默认的Q自己写的要LQ否则抛出异常。�K?/span>
}
}
可以看到q里的配|文仉面用
<property name="myHome">
<ref local="myHome"/>
</property>
注入了,否则得不到这个属性,同时Personcȝ构造方法需是默认的Q其他的要去掉,否则抛出异常?br />
?autodetect
通过beancȝ自省机制QintrospectionQ来军_是?span>constructorq是byType方式q行自动装配。如果发现默认的 构造器Q那么将使用byType方式?nbsp;
q个׃详细讲了?br />
]]> Spring?/title> http://www.aygfsteel.com/laoding/articles/237014.html老丁 老丁 Tue, 28 Oct 2008 01:25:00 GMT http://www.aygfsteel.com/laoding/articles/237014.html http://www.aygfsteel.com/laoding/comments/237014.html http://www.aygfsteel.com/laoding/articles/237014.html#Feedback 0 http://www.aygfsteel.com/laoding/comments/commentRss/237014.html http://www.aygfsteel.com/laoding/services/trackbacks/237014.html 转自Q?a >www.java114.com
Spring 作ؓ实现J2EE 的一个全方位应用E序框架Qؓ我们开发企业应用提供了一个健壮、高效的解决Ҏ。所谓全方位Q不得不说以下几个特点:
1 非R入式Q对于写代码从来不考虑复用和移植的E序员来_q一Ҏ本就没有吸引力,那么误q。所谓非侵入式是?span lang="EN-US">Spring框架?span lang="EN-US">API不会在业务逻辑上出玎ͼ也就是说我们的业务逻辑应该是纯净的,不能出现与业务逻辑无关的代码。首先针对应用而言Q这h们才能将业务逻辑从当前应用中剥离出来Q从而在其他的应用中实现复用Q其ơ针Ҏ架而言Q由于业务逻辑中没?span lang="EN-US">Spring?span lang="EN-US">APIQ所以业务逻辑也可以从Spring 框架快速的UL到其他框架?/font>
2 容器Q?span lang="EN-US">Spring提供容器功能Q容器可以管理对象的生命周期Q对象与对象之间的依赖关pR你可以写一个配|文Ӟ通常?span lang="EN-US">xml文gQ,在上面定义对象的名字Q是否是单例Q以及设|与其他对象的依赖关pR那么在容器启动之后Q这些对象就被实例化好了Q你直接ȝ好了,而且依赖关系也徏立好了?/font>
3 IOC Q控制反转,谓之“ 依赖关系的{U?span lang="EN-US">”Q如果以前都是依赖于实现Q那么现在反转ؓ依赖于抽象吧Q其实它的核心思想是要面向接口编E,至于何谓接口何谓抽象Q以及它们的好处Q多看看设计模式吧,q里׃费口舌了?/font>
4 依赖注入Q徏立对象与对象之间依赖关系的实玎ͼ包括接口注入、构造注入?span lang="EN-US">set注入Q在Spring 中只支持后两U?/font>
5 AOP Q面向方面编E,我们可以把日志、安全、事务管理等服务Q或功能Q理解成一?span lang="EN-US">“斚w” Q那么以前这些服务一直是直接写在业务逻辑的代码当中的Q这有两点不好;首先业务逻辑不纯净Q其ơ这些服务被很多业务逻辑反复使用Q完全可以剥d来做到复用。那?span lang="EN-US">AOP是q些问题的解x案,我们可以把这些服务剥d来Ş成一?span lang="EN-US">“斚w” Q以期做到复用;然后?span lang="EN-US">“斚w” 动态的插入C务逻辑中让业务逻辑能够享受到此“ 斚w” 的服?/font>
其他q有一些特点不?span lang="EN-US">Spring的核心,q里只做单陈qͼ如:?span lang="EN-US">JDBC的封装与化,提供事务理功能Q对O/R mapping 工具Q?span lang="EN-US">hibernate?span lang="EN-US">iBATISQ的整合Q提?span lang="EN-US">MVC解决ҎQ也可以与其?span lang="EN-US">web框架Q?span lang="EN-US">Struts?span lang="EN-US">JSFQ进行整合;q有?span lang="EN-US">JNDI?span lang="EN-US">mail{服务进行封装?/font>
]]> spring功能单介l?/title> http://www.aygfsteel.com/laoding/articles/227116.html老丁 老丁 Fri, 05 Sep 2008 01:15:00 GMT http://www.aygfsteel.com/laoding/articles/227116.html http://www.aygfsteel.com/laoding/comments/227116.html http://www.aygfsteel.com/laoding/articles/227116.html#Feedback 1 http://www.aygfsteel.com/laoding/comments/commentRss/227116.html http://www.aygfsteel.com/laoding/services/trackbacks/227116.html
• 目的Q解决企业应用开发的复杂?br />
• 功能Q用基本的JavaBean代替EJBQƈ提供了更多的企业应用功能
• 范围QQ何Java应用
单来_Spring是一个轻量的控制反?IoC)和面向切?AOP)的容器框架?br />
?nbsp; 轻量——从大小与开销两方面而言Spring都是轻量的。完整的Spring框架可以在一个大只?MB多的JAR文g里发布。ƈ且Spring所需的处理开销也是微不道的。此外,Spring是非侵入式的Q典型地QSpring应用中的对象不依赖于Spring的特定类?
?nbsp; 控制反{——Spring通过一U称作控制反转(IoCQ的技术促q了松耦合。当应用了IoCQ一个对象依赖的其它对象会通过被动的方式传递进来,而不是这个对象自己创建或者查找依赖对象。你可以认ؓIoC与JNDI相反——不是对象从容器中查找依赖,而是容器在对象初始化时不{对象请求就d依赖传递给它?br />
?nbsp; 面向切面——Spring提供了面向切面编E的丰富支持Q允讔R过分离应用的业务逻辑与系l服务Q例如审计(auditingQ和事务Q)理Q进行内聚性的开发。应用对象只实现它们应该做的——完成业务逻辑——仅此而已。它们ƈ不负责(甚至是意识)其它的系lx点,例如日志或事务支持?
?nbsp; 容器——Spring包含q管理应用对象的配置和生命周期,在这个意义上它是一U容器,你可以配|你的每个bean如何被创建——基于一个可配置原型QprototypeQ,你的bean可以创徏一个单独的实例或者每ơ需要时都生成一个新的实例——以及它们是如何怺兌的。然而,Spring不应该被混同于传l的重量U的EJB容器Q它们经常是庞大与笨重的Q难以用?
?nbsp; 框架——Spring可以简单的lg配置、组合成为复杂的应用。在Spring中,应用对象被声明式地组合,典型地是在一个XML文g里。Spring也提供了很多基础功能Q事务管理、持久化框架集成{等Q,应用逻辑的开发留l了你?
所有Spring的这些特征你能够编写更q净、更可管理、ƈ且更易于试的代码。它们也为Spring中的各种模块提供了基支持?
]]> spring quartz定时执行d http://www.aygfsteel.com/laoding/articles/227041.html老丁 老丁 Thu, 04 Sep 2008 11:39:00 GMT http://www.aygfsteel.com/laoding/articles/227041.html http://www.aygfsteel.com/laoding/comments/227041.html http://www.aygfsteel.com/laoding/articles/227041.html#Feedback 1 http://www.aygfsteel.com/laoding/comments/commentRss/227041.html http://www.aygfsteel.com/laoding/services/trackbacks/227041.html 首先是spring配置文g
<?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-2.0.xsd">
<!--你要执行的那个类的bean定义-->
<bean id="searchEngerneService" class="com.strongit.service.impl.SearchEngerneServiceImpl"></bean>
<!--定义定时执行searchEngerneService q个bean中的timeTask()Ҏ-->
<bean id="searchEngerneTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!--你要执行的那个方法对应的bean-->
<property name="targetObject">
<ref bean="searchEngerneService" />
</property>
<!--你要执行那个ҎQ注意方法不能有q回|参数好像也不能有-->
<property name="targetMethod">
<value>timeTask</value>
</property>
</bean>
<!--触发器的bean的设|,在这里我们设|了我们要触发的jobDetail是哪个。这里我们定义了要触发的jobDetail是searchEngerneTaskQ即触发器去触发哪个bean..q且我们q定义了触发的时?->
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="searchEngerneTask" />
</property>
<property name="cronExpression">
<!-- 关键在配|此表达式,旉讄q里表示每天晚上23Ҏ行,最后也写出了一些,具体可以自己L资料?-->
<value>0 0 23 * * ?</value>
</property>
</bean>
<!--理触发器的总设|?理我们的触发器列表,可以在bean的list中放|多个触发器?nbsp;
-->
<bean autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
</beans>
执行的那个类和方法我׃写了Q自己随便写个简单的试可以了
下面是执行主Ҏ
public class TestTimer {
/**
* @Description Ҏ实现功能描述
* @param args
* void
* @throws 抛出异常说明
*/
public static void main(String[] args) {
//q里的spring配置文g的\径自׃?/span>
ApplicationContext context = new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/application*.xml");
System.out.println("*****完毕******");
}
}
q个Ҏ的作用就是将spring跑v?br />
OK?br />
是q么?br />
Ƣ迎讨论Q!
以下是网上摘抄的一些说明:
字段 允许?/span>允许的特D字W?/span>
U?/span> 0-59 , - * /
?/span> 0-59 , - * /
时 0-23 , - * /
日期 1-31 , - * ? / L W C
月䆾 1-12 或?/span> JAN-DEC , - * /
星期 1-7 或?/span> SUN-SAT , - * ? / L C #
q_可选) 留空 , 1970-2099 , - * /
表达?/span>意义
"0 0 12 * * ?" 每天中午 12 点触?/span>
"0 15 10 ? * *" 每天上午 10:15 触发
"0 15 10 * * ?" 每天上午 10:15 触发
"0 15 10 * * ? *" 每天上午 10:15 触发
"0 15 10 * * ? 2005" 2005 q的每天上午 10:15 触发
"0 * 14 * * ?" 在每天下?/span>2 点到下午 2:59 期间的每 1 分钟触发
"0 0/5 14 * * ?" 在每天下?/span>2 点到下午 2:55 期间的每 5 分钟触发
"0 0/5 14,18 * * ?" 在每天下?/span>2 点到 2:55 期间和下?/span>6 点到 6:55 期间的每 5 分钟触发
"0 0-5 14 * * ?" 在每天下?/span>2 点到下午 2:05 期间的每 1 分钟触发
"0 10,44 14 ? 3 WED" 每年三月的星期三的下?/span>2:10 ?/span>2:44 触发
"0 15 10 ? * MON-FRI" 周一臛_五的上午 10:15 触发
"0 15 10 15 * ?" 每月 15 日上?/span>10:15 触发
"0 15 10 L * ?" 每月最后一日的上午 10:15 触发
"0 15 10 ? * 6L" 每月的最后一个星期五上午 10:15 触发
"0 15 10 ? * 6L 2002-2005" 2002 q至 2005 q的每月的最后一个星期五上午 10:15 触发
"0 15 10 ? * 6#3" 每月的第三个星期五上?/span>10:15 触发
]]>
վ֩ģ壺
|
ɳ |
|
|
|
|
ͨ |
˷ |
|
|
Ͱ |
ɽ |
Ӧ |
|
ֶ |
|
ʡ |
|
Ͷ |
|
|
|
|
綫 |
|
|
|
|
ɽ |
|
ߴ |
ɽ |
|
̨ |
ɽ |
|
ɽ |
ڳ |
|
|
Į |