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
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>
Yes, it can be just a dependency injection framework.
Here's an example with Swing: Spring & Swing
All you need is to load your context in a Main method or somwhere using ClassPathXmlApplicationContext or similar.
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml")
Yes - all you need is JVM to launch java main class that makes use of Spring FW.
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>
here is the java code example:
...
ApplicationContext context = new FileSystemXmlApplicationContext(ExecutionController.BASIC_CONFIG_FILES);
jobExplorer = (JobExplorer)context.getBean("jobExplorer");
workFlowDao = (WorkFlowDao)context.getBean("workFlowDao");
....
Good luck !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With