Spring Questions and Answers – Building a Service and Business Process with Spring

This set of Basic Java Spring questions and answers focuses on “Building a Service and Business Process with Spring”.

1. jBPM will expose beans using the:-
a) jBPM expression language
b) jBoss
c) Spring expression language
d) None of the mentioned
View Answer

Answer: a
Explanation: jBPM will expose beans using the jBPM expression language, and you can then just reference them by name.

2. jBPM, and indeed most workflow engines, passivate state for you, allowing a process to wait on external events :-
a) True
b) False
View Answer

Answer: a
Explanation: Indeed, because you’ve decomposed your process into a series of isolated steps, each of which contributes to the larger goal while remaining independently useful, you get the best of both worlds:
stateful processes and stateless scalability.

3. We override the List bean (with id annotatedHibernateClasses) that we created for the last recipe (jbpm4 context.xml) to provide the session factory with a collection of annotated entities which is here as:-

advertisement
advertisement
<?xml version="1.0" encoding="UTF-8"?>
	<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:util="http://www.springframework.org/schema/util" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/util
	http://www.springframework.org/schema/util/spring-util-3.0.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	">
	<import resource="jbpm4-context.xml"/>
	<context:annotation-config/>
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
	<tx:attributes>
	<tx:method propagation="REQUIRED" name="*"/>
	</tx:attributes>
	</tx:advice>
	<aop:config>
	<aop:advisor advice-ref="txAdvice" pointcut="execution(* 
	com.apress.springrecipes..jbpm4.*.*(..))"/>
	</aop:config>
	<util:list id="annotatedHibernateClasses">
	<value>com.apress.springrecipes.jbpm.jbpm4.customers.Customer</value>
	</util:list>
	<bean id="customerService" class="com.apress.springrecipes.jbpm.jbpm4.customers.
	CustomerServiceImpl">
	<property name="processDefinitions">
	<list>
	<value>/process-definitions/RegisterCustomer.jpdl.xml</value>
	</list>
	</property>
        </bean>
</beans>

a) HibernateCustom
b) Customer
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: b
Explanation: This bean leverages Hibernate (through the HibernateTemplate instance) to handle persistence, and it leverages jBPM (through the SpringConfiguration instance) to handle BPM.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. The method annotated with @PostConstruct will be run after the bean’s been configured to let the user inject custom initialization logic.
a) True
b) False
View Answer

Answer: a
Explanation: The bean handles as part of its duties in its post-initialization phase.

5. The business process file’s name needs to end in :-
a) jpdl
b) xml
c) jpdl.xml
d) none of the mentioned
View Answer

Answer: c
Explanation: The business process file’s name needs to end in jpdl.xml; otherwise, jBPM won’t deploy it.
advertisement

6. At the top, we’ve injected some dependencies:
a) springConfiguration
b) repositoryService
c) executionService
d) all of the mentioned
View Answer

Answer: d
Explanation: At the top, we’ve injected three dependencies:
springConfiguration (which doesn’t get used, though its configuration is worth noting because you may use it to access other services), repositoryService, and executionService.

7. The class(CustomerServiceImpl) provides a few salient methods:-

advertisement
package com.apress.springrecipes.jbpm.jbpm4.customers;
public interface CustomerService {
void sendWelcomeEmail(Long customerId);
void deauthorizeCustomer(Long customerId);
void authorizeCustomer(Long customerId);
Customer getCustomerById(Long customerId);
Customer createCustomer(String email, String password, String firstName, 
String lastName);
void sendCustomerVerificationEmail(Long customerId);
}

a) void setupProcessDefinitions()
b) Customer createCustomer(String email, String passphrase, String firstName, String lastName)
c) void sendCustomerVerificationEmail(Long customerId)
d) all of the mentioned
View Answer

Answer: d
Explanation: The class provides a few
salient methods (some of which are required by its interface, CustomerService):
• void setupProcessDefinitions()
• Customer createCustomer(String email, String passphrase, String firstName,
String lastName)
• void sendCustomerVerificationEmail(Long customerId)
• void authorizeCustomer(Long customerId)

8. In the bean, setupProcessDefinitions is run when the bean is created.
a) True
b) False
View Answer

Answer: a
Explanation: It iterates through the processDefinitions collection and deploys the resource whose path it is given.

9. Process definition will reference Spring beans using the JBoss expression language.
a) True
b) False
View Answer

Answer: a
Explanation: We’ll walk through how the business process uses our customerService bean and how the customerService bean uses the business process to handle the customer’s sign-up.

10. In jBPM, a business process is built using jPDL.
a) True
b) False
View Answer

Answer: a
Explanation: You can use the Eclipse plug-in to model jBPM processes, but the jPDL schema is so simple that you don’t really need it.

11.In the customerService bean, a client will use createCustomer to create a customer record.

<?xml version="1.0" encoding="UTF-8"?>
<process name="RegisterCustomer" xmlns="http://jbpm.org/4.0/jpdl">
          <start>
          <transition to="send-verification-email" />
          </start>
          <java name="send-verification-email" expr="#{customerService}"
          method="sendCustomerVerificationEmail">
          <arg> <object expr="#{customerId}" /> </arg>
          <transition to="confirm-receipt-of-verification-email" />
          </java>
          <state name="confirm-receipt-of-verification-email">
          <transition to="send-welcome-email" />
          </state>
          <java name="send-welcome-email"
          expr="#{customerService}" method="sendWelcomeEmail">
          <arg> <object expr="#{customerId}" /> </arg>
          </java>
</process>

a) True
b) False
View Answer

Answer: a
Explanation: In a real-world example, you might imagine exposing these services as a SOAP endpoint to be consumed by various clients, such as a web application or other business applications.

12.Inside the createCustomer method, we use jBPM to start the business process to track the Customer. This is done with the :-

<?xml version="1.0" encoding="UTF-8"?>
<process name="RegisterCustomer" xmlns="http://jbpm.org/4.0/jpdl">
          <start>
          <transition to="send-verification-email" />
          </start>
          <java name="send-verification-email" expr="#{customerService}"
          method="sendCustomerVerificationEmail">
          <arg> <object expr="#{customerId}" /> </arg>
          <transition to="confirm-receipt-of-verification-email" />
          </java>
          <state name="confirm-receipt-of-verification-email">
          <transition to="send-welcome-email" />
          </state>
          <java name="send-welcome-email"
          expr="#{customerService}" method="sendWelcomeEmail">
          <arg> <object expr="#{customerId}" /> </arg>
          </java>
</process>

a) startProcessInstanceByKey
b) startProcessInstance
c) all of the mentioned
d) none of the mentioned
View Answer

Answer: a
Explanation: In the invocation, we give jBPM variables through a Map instance (acting as something of a context for the process variables).

13. Once in the java element named send-verification-email, jBPM will invoke the method:-
a) sendCustomerVerificationEmail
b) sendCustomerVerification
c) veifyCustomerVerificationEmail
d) all of the mentioned
View Answer

Answer: a
Explanation: Once in the java element named send-verification-email, jBPM will invoke the method sendCustomerVerificationEmail on the customerService bean in Spring.

14. Inside authorizeCustomer, the service queries the server for the any processes waiting at the:-
a) confirm-receipt-of-verification
b) confirm-receipt
c) confirm-receipt-of-verification-email
d) none of the mentioned
View Answer

Answer: c
Explanation: Inside authorizeCustomer, the service queries the server for the any processes waiting at the confirm-receipt-of-verification-email state and having this customer’s ID.

15. The authorizeCustomer method also updates the Customer entity, marking it as authorized. From there, execution proceeds to the send-welcome-email java element.
a) True
b) False
View Answer

Answer: a
Explanation: As before, the java element will be used to invoke a method on the customerService bean. This time, it will invoke sendWelcomeEmail to send the newly registered Customer a welcome email.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice basic questions on all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.