我有一个应该只在标准JVM上运行的应用程序 - 没有像JBoss或Tomcat这样的应用程序服务器。是否可以通过spring-jdbc
正常配置Spring(我需要applicationContext.xml
)来运行它?我还没有找到任何教程。
SOLUTION
第一部分来自下面的答案,第二部分是(在我的情况下)将其添加到pom.xml
。
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>package.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
答案 0 :(得分:6)
是的,它可能只是一个依赖注入框架。
以下是Swing的示例:Spring & Swing
您只需要使用ClassPathXmlApplicationContext或类似方法在Main方法或somwhere中加载上下文。
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml")
答案 1 :(得分:4)
是的 - 所有你需要的是JVM来启动使用Spring FW的java主类。
这是context.xml的示例和使用它来初始化Spring JDBC的代码:
<!-- DATASOURCE used for object stores -->
<bean id="dataSourceForObjects" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.${job.repository.db.type}.jdbc.Driver" />
<property name="url" value="jdbc:${job.repository.db.type}://${db.host}:${job.repository.db.port}/${db.schema}" />
<property name="username" value="${db.user}" /> <!-- your user id. e.g. root-->
<property name="password" value="${db.password}" /> <!-- your password-->
<property name="maxIdle" value="10" />
<property name="maxActive" value="100" />
<property name="maxWait" value="10000" />
<property name="validationQuery" value="select 1" />
<property name="testOnBorrow" value="false" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1200000" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="numTestsPerEvictionRun" value="5" />
<property name="defaultAutoCommit" value="true" />
</bean>
<bean id="objectStoreDao" class="com.pursway.core.dao.objectStore.ObjectStoreJdbcImpl">
<property name="dataSource" ref="dataSourceForObjects"/>
</bean>
这是java代码示例:
...
ApplicationContext context = new FileSystemXmlApplicationContext(ExecutionController.BASIC_CONFIG_FILES);
jobExplorer = (JobExplorer)context.getBean("jobExplorer");
workFlowDao = (WorkFlowDao)context.getBean("workFlowDao");
....
祝你好运!