是否可以在没有应用程序服务器的情况下运行Spring? [英] Is it possible to run Spring without an application server?
问题描述
我有一个应该只在标准JVM上运行的应用程序 - 没有像JBoss或Tomcat这样的应用程序服务器。是否可以通过 applicationContext.xml
正常配置Spring(我需要 spring-jdbc
)来运行它?我还没有找到任何教程。
I have an application which should run only on standard JVM - no application servers like JBoss or Tomcat. Is it possible to run it with Spring (I need spring-jdbc
) configured normally through applicationContext.xml
? I havent't found any tutorial.
SOLUTION
第一部分来自下面的答案,第二部分是(在我的例子中)将其添加到 pom.xml
中。
First part is from the answers below and the second part is (in my case) adding this into 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>
推荐答案
是的 - 所有你需要的是JVM来启动java main使用Spring FW的类。
Yes - all you need is JVM to launch java main class that makes use of Spring FW.
这里是context.xml的例子和用它来初始化Spring JDBC的代码:
here is the example of context.xml and a code that uses it to initialize 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代码示例:
here is the java code example:
...
ApplicationContext context = new FileSystemXmlApplicationContext(ExecutionController.BASIC_CONFIG_FILES);
jobExplorer = (JobExplorer)context.getBean("jobExplorer");
workFlowDao = (WorkFlowDao)context.getBean("workFlowDao");
....
祝你好运!
这篇关于是否可以在没有应用程序服务器的情况下运行Spring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!