把spring配置打包到jar包里提供给不同消费者使用 2007-08-01 09:19:09

 第一步

将spring配置打包写好
书写beanRefContext.xml
demo
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans default-autowire="no" default-lazy-init="false"
    default-dependency-check="none">

    <bean id="businessBeanFactory"
        class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
            <list>
                <value>applicationContext-datasource.xml</value>
                <value>applicationContext-hibernate.xml</value>
                <value>applicationContext-service.xml</value>
                <value>applicationContext-xstream.xml</value>
            </list>
        </constructor-arg>
    </bean>
   
    <bean id="ear.context"
        class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
            <list>
                <value>applicationContext-quartz.xml</value>
                <value>applicationContext-ibmmq-client.xml</value>
                <value>applicationContext-jms-client.xml</value>
                <value>applicationContext-xstream.xml</value>
                <value>applicationContext-mail.xml</value>
            </list>
        </constructor-arg>
    </bean>
   
</beans>

此jar包命名为service.jar包,service.jar包位于ear包中并确保ejb的ejb.manifest.classpath中存在
businessBeanFactory 提供给ejb
在spring对ejb支持的类中

    public void setMessageDrivenContext(
            MessageDrivenContext messageDrivenContext) {
        super.setMessageDrivenContext(messageDrivenContext);
        String locatorFactorySelector = null;
        String beanFactoryLocatorKey = null;
        try {
            locatorFactorySelector = (String) new JndiTemplate()
                    .lookup("java:comp/env/locatorFactorySelector");
        } catch (NamingException e) {
            e.printStackTrace();
        }

        setBeanFactoryLocator(locatorFactorySelector != null ? ContextSingletonBeanFactoryLocator
                .getInstance(locatorFactorySelector)
                : ContextSingletonBeanFactoryLocator.getInstance());// 指定默认的beanRefContext.xml

        try {
            beanFactoryLocatorKey = (String) new JndiTemplate()
                    .lookup("java:comp/env/beanFactoryLocatorKey");
        } catch (NamingException e) {
            e.printStackTrace();
        }
        setBeanFactoryLocatorKey(beanFactoryLocatorKey != null ? beanFactoryLocatorKey
                : "businessBeanFactory");
    }


ejb配置

<description>ejb</description>
   <display-name>ejb</display-name>
      <enterprise-beans>
       <message-driven id="MessageDriven_1">
         <description>yourEJB</description>
         <display-name>Name for
yourEJB</display-name>
         <ejb-name>yourEJB</ejb-name>
         <ejb-class>com.corp.YourEJB</ejb-class>
         <transaction-type>Bean</transaction-type>        
         <message-driven-destination>
            <destination-type>javax.jms.Queue</destination-type>
         </message-driven-destination>
     <env-entry>
          <env-entry-name>locatorFactorySelector</env-entry-name>
          <env-entry-type>java.lang.String</env-entry-type>
          <env-entry-value>classpath*:beanRefContext.xml</env-entry-value>
      </env-entry>
      <env-entry>
          <env-entry-name>beanFactoryLocatorKey</env-entry-name>
          <env-entry-type>java.lang.String</env-entry-type>
          <env-entry-value>businessBeanFactory</env-entry-value>
      </env-entry>
      </message-driven>
    </enterprise-beans>
   
    <assembly-descriptor id="AssemblyDescriptor_1">
       </assembly-descriptor>
</ejb-jar>  

//传入参数指定加载的bean工厂的名字

ear.context 提供给web

service.jar必须存在web的lib下或者在
manifest.classpath
ejb中这样加载
<context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>classpath*:beanRefContext.xml</param-value>
</context-param>
<context-param>
        <param-name>parentContextKey</param-name>
        <param-value>ear.context</param-value>
</context-param>
<!--但我不知道再加载另外的配置能否跟其融和在一起?
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-blank.xml</param-value>
</context-param>
-->

<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>

Spring2.0中的定时调度(Scheduling)使用OpenSymphony Quartz调度器使用笔记2007-01-22 15:40:49

Spring2.0中的定时调度(Scheduling)使用OpenSymphony Quartz调度器使用笔记
1)、加入spring-framework-2.0.2libquartzquartz-1.6.0.jar 包
2)、使用commons-collections-3.1.jar,不要使用旧的commons-collections-2.1.1.jar
3)、书写Job实现类
package example
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class ExampleJob extends QuartzJobBean{
 protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
  
  //System.out.println(System.currentTimeMillis());
  //dofoo
 }
 private int timeout;
   public void setTimeout(int timeout) {
     this.timeout = timeout;
   }
}
4)、书写beans.xml
<?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:util="http://www.springframework.org/schema/util"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/util http://www.springframework.org/schema/util/spring-util-2.0.xsd      
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean name="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass" value="example.ExampleJob" />
  <property name="jobDataAsMap">
    <map>
      <entry key="timeout" value="5" />
    </map>
  </property>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <!-- see the example of method invoking job above -->
    <property name="jobDetail" ref="jobDetail" />
    <!-- 10 seconds -->
    <property name="startDelay" value="10000" />
    <!-- repeat every 50 seconds -->
    <property name="repeatInterval" value="50000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="simpleTrigger" />
        </list>
    </property>
</bean>
</beans>      

Spring2.0 Groovy Exception org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: 2007-01-20 18:53:03

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'calculator' defined in file [D:eclipse-SDK-3.2.1-win32workspace*buildexploded-earAPP-INFclassesapplicationContext-service-groovy.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine implemented interfaces of missing type GroovyCalculator
 [Xlint:cantFindType]
Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine implemented interfaces of missing type GroovyCalculator
 [Xlint:cantFindType]
 at org.aspectj.weaver.reflect.ReflectionWorld$ExceptionBasedMessageHandler.handleMessage(ReflectionWorld.java:163)
 at org.aspectj.weaver.Lint$Kind.signal(Lint.java:276)
 at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.raiseCantFindType(MissingResolvedTypeWithKnownSignature.java:198)
 at org.aspectj.weaver.MissingResolvedTypeWithKnownSignature.getDeclaredInterfaces(MissingResolvedTypeWithKnownSignature.java:76)
 at org.aspectj.weaver.ResolvedType.getDirectSupertypes(ResolvedType.java:64)
 at org.aspectj.weaver.JoinPointSignatureIterator.findSignaturesFromSupertypes(JoinPointSignatureIterator.java:164)
 at org.aspectj.weaver.JoinPointSignatureIterator.hasNext(JoinPointSignatureIterator.java:69)
 at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:287)
 at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:106)
 at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:146)
 at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:235)
 at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:101)
 at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:92)
 at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:304)
 at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:190)
 at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:188)
 at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:231)
 at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:256)
 at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:68)
 at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:54)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:247)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:311)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:367)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:290)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
 at org.springframework.scripting.groovy.Groovy.main(Groovy.java:12)

 beans.xml

<?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:lang="http://www.springframework.org/schema/lang"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-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/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd     
       ">

 <!-- 
    <lang:groovy id="calculator" script-source="classpath:calculator.groovy"/>
    -->


<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"/>

<bean id="calculator" class="org.springframework.scripting.groovy.GroovyScriptFactory">
        <constructor-arg>
            <!-- 
            <value>inline:
package org.springframework.scripting.groovy;
import org.springframework.scripting.Calculator
class GroovyCalculator implements Calculator {
    int add(int x, int y) {
       return x + y;
    }
}
            </value>
           
            -->
            <value>calculator.groovy</value>
        </constructor-arg>
    </bean>

</beans>

一旦加入 <aop:config> </aop:config>(下列红色部分)的事务声明就会报上述错误

 <tx:advice id="txAdvice-baseService" transaction-manager="txManager">
  <tx:attributes>
   <tx:method name="save*" />
   <tx:method name="update*" />
   <tx:method name="get*" read-only="true"/>
   <tx:method name="find*" read-only="true" />
   <tx:method name="*" propagation="SUPPORTS" read-only="false" />
  </tx:attributes>
 </tx:advice>
 
 
 
  
 <aop:config>
  <aop:pointcut id="employeeServiceMethods" expression="execution(* webapp.service.EmployeeService.*(..))" />
  <aop:advisor advice-ref="txAdvice-baseService" pointcut-ref="employeeServiceMethods" />
 </aop:config>


 <aop:config proxy-target-class="false">
  <aop:pointcut id="baseServiceMethods" expression="execution(* webapp.service.BaseService.*(..))" />
  <aop:advisor advice-ref="txAdvice-baseService" pointcut-ref="baseServiceMethods" />
 </aop:config>

:(

asm.jar包问题 冲突 Hibernate and Spring groovy2007-01-20 16:59:18

asm.jar包问题

问题描述

Hibernate3.2ga版本需要的最小依赖包的asm.jar版本很低

Spring对groovy的scipting支持最要asm2.2.jar版本高,一些类有问题

链接 http://forum.springframework.org/showthread.php?t=26713 Spring 2.0 AOP: ASM Dependencies

解决办法

Try this - use cglib_nodep jar instead of simple cglib - the jar includes the required asm dependencies so it will not require any asm jar inside the classpath.
If you still require asm (for some other library) then try using the latest stable/production release - 2.2.2 or 2.2.3 I think. There is an asm-all.jar which includes all asm packages.

cglib-nodep-2.1_3.jar

asm-all-2.2.3.jar

这样hibernate就不需要旧的asm.jar文件了

这样groovy就能用新的asm2.2.jar啦

这样就能把service impl用动态语言groovy实现了

:)

可惜Tapestry还不能和Groovy结合

http://groovestry.sourceforge.net/ 太陈旧了

 

 

 

Failed to convert property value of type [$Proxy10] to required type2007-01-05 22:32:00

Failed to convert property value of type [$Proxy10] to required type

acegi spring2.0 错误

Failed to convert property value of type [$Proxy10] to required type
acegi spring


原因见 http://forum.springframework.org/archive/index.php/t-19176.html
去掉我的拦截机没错误了 

Spring2.0 整合ejb2.0 备忘录2006-12-27 22:24:40

如果ejb需要使用spring中的bean实现 那么需要加载得到bean工厂,继承 org.springframework.ejb.support.AbstractStatelessSessionBean

实现setSessionContext(SessionContext sessionContext) 以拿到spring的beans

如果ejb不需要使用spring的beans那就是旧有的实现了,

spring还可以简化得到ejb客户端的过程,使用EJB的业务方法接口(Business Methods Interface)模式

整合 acegi-security-1.0.3 springframework-2.0 Hibernate3.2GA备忘2006-12-23 13:12:23

整合 acegi-security-1.0.3 springframework-2.0 Hibernate3.2GA备忘

学着  实战Acegi:使用Acegi作为基于Spring框架的WEB应用的安全框架 实战了一下,改了一点东西

 

XFire 1.2.3和Spring 2.0试用备忘 2006-12-23 10:19:42

环境 

Codehaus XFire 1.2.3

http://xfire.codehaus.org/Download 

Spring 2.0

JDK1.4.2

Tomcat5.0.28 

下载 xfire-distribution-1.2.3.zip 把所有的依赖lib 拿出来

跑它的 xfire-1.2.3/examples/spring 这个例子

不要按照 examples/book 这个例子把xfire配置到 META-INF/xfire/service.xml 这样配置,好像跟spring2.0跑不起来

在weblogic8.1.3下发布记得要把 stax-api-1.0.1.jar包提前加载,Xfire需要新的QName类,在webloigc里边包含旧的API

Spring2.0错误笔记2006-12-10 00:21:53

1)org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. One of '{"http://www.springframework.org/schema/beans":prop}' is expected.

2)Caused by:
org.xml.sax.SAXParseException: The content of element type "property" must match "(description?,(bean|ref|idref|value|null|list|set|map|props)?)".

3)org.springframework.beans.factory.BeanDefinitionStoreException: Line 15 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Caused by:
org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
 at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)


4)org.xml.sax.SAXParseException: The prefix "tx" for element "tx:advice" is not bound.


5)org.xml.sax.SAXParseException: Element type "tx:advice" must be declared.


1)和2)因为元素书写错误比如<props></props>能包含<prop></prop>但不能包含<property></property>
3)<?xml version="1.0" encoding="UTF-8"?>这一行必须放到第一行
4)头部丢了tx声明
5)头部声明丢了schemaLocation

<?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:util="http://www.springframework.org/schema/util"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="