いくつかのJavaSpringBeanをロードして実行するために、このGroovyスクリプトを作成しました。
@GrabResolver(name = 'libs.snapshot', root = 'http://ml1002pc:8081/artifactory/libs-snapshot', m2compatible = 'true')
@Grapes([
@Grab(group = 'com.siemens.soarian.sf', module = 'BuildInformationService', version = '1.0-SNAPSHOT', changing = true),
@Grab(group = 'com.siemens.soarian.sf', module = 'GapAnalyzer', version = '1.0-SNAPSHOT', changing = true)
])
@GrabResolver(name = 'libs-release', root = 'http://ml1002pc:8081/artifactory/libs-release', m2compatible = 'true')
@Grapes([
@Grab(group = 'org.springframework', module = 'org.springframework.context', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.context.support', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.core', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.beans', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.asm', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.aop', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.aspects', version = '3.0.5.RELEASE'),
@Grab(group = 'org.springframework', module = 'org.springframework.expression', version = '3.0.5.RELEASE'),
@Grab('org.apache.commons:commons-lang:2.6'),
@Grab('org.apache.commons:commons-collections:3.2.1'),
@Grab('org.apache.commons:commons-logging:1.1.1'),
@Grab('org.apache.commons:commons-dbcp:1.4'),
@Grab('org.apache.commons:commons-pool:1.6'),
@Grab('com.microsoft:sqljdbc:1.2'),
])
@GrabConfig(systemClassLoader = true)
import java.util.Collection;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.siemens.soarian.sf.build.BuildInformationService;
import com.siemens.soarian.sf.gap.*
public class CommandLineWrapper {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:**/META-INF/applicationContext*.xml");
GapAnalyzer gapAnalyzer = (GapAnalyzer) ctx.getBean("gapAnalyzer");
}
}
ロードしようとしているアプリケーションコンテキストには、次のBean宣言があります。
<bean id="gapAnalyzer" class="com.siemens.soarian.sf.gap.GapAnalyzerImpl">
<constructor-arg ref="buildInformationService"/>
</bean>
コマンドラインで取得する例外は次のとおりです。
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@14f1726: startup date [Mon Jan 21 10:46:04 EST 2013 ]; root of context hierarchy
Jan 21, 2013 10:46:04 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e22c75: defining beans []; root of factory hierarchy
Caught: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'gapAnalyzer' is defined
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'gapAnalyzer' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
at org.springframework.beans.factory.BeanFactory$getBean.call(Unknown Source)
ただし、このスクリプトを実行すると、SpringがBeanの仕様を見つけられないかのように、40行目にNoSuchBeanDefinitionExceptionが発生します。
Javaで記述され、Eclipseで実行されているSpring部分統合テストを使用すると、Beanとその他の必要なBeanを正常にロードできます。期待どおりにロードされます。
Windows Home /.groovyにあるGrapeによってダウンロードされたjarを調べたところ、すべてのjarが存在しています。
クラスパスに物を追加するという私の読書に基づいて、グレープはこれらのjarファイルをクラスパスに配置するように注意する必要があります。
私は走っています:
- Windows XP
- Eclipse Juno
- Groovy 2.0.6
- Sun JVM:1.6.0_33
- 春3.0.5。リリース
- アーティファクトリー2.3.4