且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以在没有应用程序服务器的情况下运行Spring?

更新时间:2022-11-16 20:53:23

是的 - 所有你需要的是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");
....

祝你好运!