이 콘텐츠는 선택한 언어로 제공되지 않습니다.
13.3. Spring
A Spring XML configuration file can be used to easily define and configure knowledge bases and sessions in a Spring environment, making it possible to access a session and invoke processes from within a Spring application.
The Example SPring Configuration File below sets up a new session based on a knowledge base with one process definition loaded from the classpath.
Example 13.2. Example Spring Configuration File
The following code loads the above Spring configuration, retrieves the session, and starts the process:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-conf.xml"); StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) context.getBean("ksession"); ksession.startProcess("com.sample.HelloWorld");
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("spring-conf.xml");
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) context.getBean("ksession");
ksession.startProcess("com.sample.HelloWorld");
Note that you can also inject the session in one of your domain objects; for example, add the following fragment in the configuration file:
<bean id="myObject" class="org.jbpm.sample.MyObject"> <property name="session" ref="ksession" /> </bean>
<bean id="myObject" class="org.jbpm.sample.MyObject">
<property name="session" ref="ksession" />
</bean>
As a result, the session will be injected into the domain object and can then be accessed directly. For example: