Download Pivotal Certified Professional Spring Developer Exam: A Study Guide PDF

TitlePivotal Certified Professional Spring Developer Exam: A Study Guide
File Size9.4 MB
Total Pages477
Table of Contents
                            Contents at a Glance
About the Author
About the Technical Reviewer
Chapter 1: Book Overview
	What Is Spring and Why Should You Be Interested in It?
	What Is the Focus of This Book?
	Who Should Read This Book?
	About the Certification Exam
	How to Use This Book as a Study Guide
	How Is This Book Structured ?
		How Each Chapter Is Structured
			Downloading the Code
			Contacting the Author
	Recommended Development Environment
		Recommended JVM
		Recommended Project Build Tool
		Recommended IDE
		The Project Sample
Chapter 2: Spring Bean LifeCycle and Configuration
	Old Style Application Development
	Spring IoC and Dependency Injection
	Spring Configuration
		Providing Configuration via XML
			Constructor Injection
			Setter Injection
			Injecting Dependencies That Are Not Beans
			Using Bean Factories
			Creating an Application Context
		Spicing Up XML Configuration
			Spring Namespaces
			How to Read Property Files in Spring Evolution
			Spring Expression Language
			Bean Definition Inheritance
			Inner beans
			Bean Naming
		Application Context and Bean Lifecycle
			Bean Lifecycle Under the Hood
			Bean Scopes
		Providing Configuration Using Java Configuration and Annotations
			The Annotations
			Using Multiple Sources of Configuration
			Bean Naming
			Field, Constructor, and Setter Injection
			Injecting Dependencies That Are Not Beans
			Bean Lifecycle and Scopes
			Bean Definitions Loading
			Bean Creation
			Injecting Dependencies
			Bean Destruction
	2.1 Quick quiz
Chapter 3: Testing Spring Applications
	A Few Types of Testing
	Test-Driven Development
	Unit and Integration Testing
		Testing with Stubs
		Testing with Mocks
	3.1 Testing with Spring
		Using Profiles
	Quick Quiz
	Practical Exercise
Chapter 4: Aspect Oriented Programming with Spring
	Problems Solved by AOP
	Spring AOP
		AOP Terminology
		Quick Start
		Aspect Support Configuration using XML
		Defining Pointcuts
		Implementing Advice
			After Returning
			After Throwing
	Quick Quiz
	Practical Exercise
Chapter 5: Data Access
	Basic Data Access Using JDBC
	Spring Data Access
		Introducing JdbcTemplate
			Querying with JdbcTemplate
			Querying with NamedParameterJdbcTemplate
		Spring Data Access Exceptions
	Data Access Configuration In a Transactional Environment
	How Transaction Management Works in Spring
		Configure Transactions Support
			Testing transactional methods
			Making Third-Party Components Transactional
			! Spring Declarative Model Clarification
			Spring Programatic Transaction Model
			**Distributed Transactions
	Introducing Hibernate and ORM
		Session and Hibernate Configuration
		Session and Hibernate Querying
		Exception Mapping
		Object Relational Mapping
		Java Persistence API
			Configure Spring and JPA with Hibernate support
			JPA Querying
			Advanced JPA, JTA, JNDI
	Spring Data JPA
		**Spring and MongoDB
Chapter 6: Spring Web
	Spring Web App Configuration
		Java Configuration for Spring MVC
		Getting Rid of web.xml
		Running a Spring Web Application
		Running with Jetty
		Running with Tomcat
	Spring Security
		Spring Security Configuration
		XML Configuration
		Spring XML Configuration without web.xml
		Java Configuration
		Security Tag Library
		Method Security
	Spring Boot
		Configuration Using YAML
		Testing with Spring Boot
Chapter 7: Spring Advanced Topics
	Spring Remoting
		Spring Remote Configuration
	Spring JMS
		JMS Connections and Sessions
		JMS Messages
		JMS Destinations
		Apache ActiveMQ
		Spring JmsTemplate
		JMS with Spring Boot
	Spring Web Services
		SOAP Messages
		Generating Java Code with XJC
		Spring Boot WS Application
		Publishing WSDL
		Testing Web Services applications
	Spring REST
		Spring Support for REST
		Exception Handling
		HTTP Message Converters
		Spring MVC Configuration for RESTful Applications
		Using RestTemplate to Test RESTful Applications
		Advantages of REST
			Practice Section
			RESTful Spring Application with Spring Boot
	Spring JMX
	JMX Architecture
		Plain JMX
		Spring JMX
	Quick Quiz
Chapter 8: Spring Microservices with Spring Cloud
	Microservices with Spring
		Registration and Discovery Server
		Microservices Development
		Microservices Communication
	More Novelties
		Practice Section
	Quick Quiz
Document Text Contents
Page 1

F O R P R O F E S S I O N A L S B Y P R O F E S S I O N A L S®


Shelve in:
Programming Languages/Java

User level:

Pivotal Certified
Professional Spring
Developer Exam

A Study Guide

Examination preparation on core Spring
concepts and principles

Iuliana Cosmina

Pass the Pivotal Certified Professional exam using source code examples, study summaries,
and mock exams. In this book, you’ll find a descriptive overview of certification-related Spring
modules and a single example application demonstrating the use of all required Spring
modules. Also, it is suitable as an introductory primer for Spring newcomers.

Furthermore, in Pivotal Certified Professional Spring Developer Exam: A Study Guide each
chapter contains a brief study summary and question set, and the book’s free downloadable
source code package includes one mock exam (50 questions – like a real exam). After using this
study guide, you will be ready to take and pass the Pivotal Certified Professional exam.

When you become Pivotal Certified, you will have one of the most valuable credentials in Java.
The demand for Spring skills is skyrocketing. Pivotal certification helps you advance your skills
and your career, and get the maximum benefit from Spring. Passing the exam demonstrates your
understanding of Spring and validates your familiarity with: container-basics, aspect oriented
programming (AOP), data access and transactions, Spring Security, Spring Boot, microservices
and the Spring model-view-controller (MVC). Good luck!

• How to understand the core principles of the popular Spring Framework
• How to use dependency injection
• How to work with aspects in Spring and do AOP (aspect oriented programming)
• How to control transactional behavior and work with SQL and NoSQL (MongoDB) databases
• How to create and secure web applications based on Spring MVC
• How to create Spring microservices applications
• How to get to know the format of exam and type of questions in it

Pivotal Certified Professional Spring Developer Exam


Pivotal Certified Professional Spring D
eveloper Exam

9 781484 208120

ISBN 978-1-4842-0812-0

Related Titles

Page 2

Pivotal Certified
Professional Spring

Developer Exam
A Study Guide

Iuliana Cosmina

Page 238

Chapter 5 ■ Data aCCess


Before Spring 4.0, the @TransactionConfiguration could be used on a test class used to define the
transactional context for tests. It became deprecated in Spring 4.0, with the introduction of profiles and @
EnableTransactionManagement. But in case you are interested in an example, here it is:

import org.springframework.test.context.transaction.TransactionConfiguration;
@TransactionConfiguration(defaultRollback = false,
transactionManager = "txManager")
public class TransactionalJdbcRepoTest {
public void testFindById() {
User user = userRepo.findById(1L);
assertEquals("John", user.getUsername());

The default value for the defaultRollback attribute is true, and it was set to false in the previous
example just to introduce this attribute.

Another useful test annotation is @BeforeTransaction, which can be used to set up or check a test
environment before executing the transactional test method. The @Before annotated method is executed in
the context of the transaction. The method in the following code snippet checks that the test database was
initialized properly outside of a transaction context.

import org.springframework.test.context.transaction.BeforeTransaction;
@ContextConfiguration(classes = {TestDataConfig.class, AppConfig.class})
public class UserServiceTest {
public void checkDbInit(){
int count = userService.countUsers();
assertEquals(4, count);

Making Third-Party Components Transactional
For situations in which annotations cannot be used to configure transactional execution, this being the
case when a version earlier than Java 1.5 is used or the service is a third-party implementation that cannot
be changed, the Spring transaction management configuration can be achieved using XML to declare a
combination of AOP and tx configuration elements.

<beans ..>
<!-- daraSource bean -->
<bean id="dataSource"
<property name="driverClass" value="org.h2.Driver"/>

Page 239

Chapter 5 ■ Data aCCess


<property name="url" value="jdbc:h2:test"/>
<property name="username" value="test"/>
<property name="password" value="test"/>

<!-- target bean -->
<bean id="userService" class="...UserServiceImpl" />

<!-- transaction manager bean -->
<bean id="transactionManager"
<property name="dataSource" ref="dataSource"/>

<!-- AOP pointcut to select target methods -->
<aop:pointcut id="allMethods"
<aop:advisor pointcut-ref="userService"
advice-ref="transactionalAdvice" />

<!-- Transactional Around advice -->
<tx:advice id="transactionalAdvice">
<tx:method name="find*" read-only="true" timeout="10"/>
<tx:method name="update*" read-only="false" timeout="30"/>

! If you want to test your understanding of spring transaction management, you can open now the 06-ps-tx-
practice project and try to complete the tODOs. there are five tasks for you to solve, numbered from 31 to 35.
the parts missing are marked with a tODO task and are visible in Intellij IDea in the tODO view.

task tODO 31, located in the TestDataConfig class, requires you to define a transaction manager bean to be
used to mange transactions.

task tODO 32, located in the AppConfig class, requires you to enable use of declarative transactions.

task tODO 33, located in UserServiceImpl, requires you to make all the methods transactional.

task tODO 34, located in class UserServiceImpl, requires you to complete the transaction definition of the
updatePassword(...) method, to make the transaction writable, and to roll back for the checked exception
thrown by the method.

task tODO 35, located in test class UserServiceTest, requires you to complete the body of the method testing
the userService.updatePassword(...) method.

If you have trouble, you can take a peek at the proposed solution in the 06-ps-tx-solution project.

Page 476



memory datasources, 54
read properties, 54
typed collections, 53
util namespace, 53

reading properties
advantage, 56
bean namespace, 55
context file, 55
util namespace, 56

schema declaration, 29
XML configuration

application context, 48–52
bean definition, 30
bean factories, 45–47
constructor injection, 31–34
dependency injection, 38–39, 41, 43–45
setter injection, 34–37
XML-based metadata, 29

Spring data access

branches, 208
data sources, 207
hierarchy, 207
non-transient, 208
TODO view, 209
transient, 208

JdbcTemplate (see JdbcTemplate)
repository classes interact, 189
transaction management

atomic execution, 218–219
@BeforeTransaction, 226
conceptual UML sequence diagram, 213–214
configuration support, 214
console log, 220
declarative model clarification, 228–232
declare transactional methods, 215–217
dirty reads, 221
distributed transaction, 233–234
isolation attribute, 221
manager framework, 213
nested transaction, 218, 220
noRollbackFor attribute values, 222
phantom reads, 222
programatic transaction model, 232–233
propagation attribute, 218
readOnly attribute, 217
repeatable read, 221
@Rollback annotation, 225
rollbackFor attribute values, 222
serialization, 222
testing methods, 223–225
third-party implementation, 226–227
@Transactional annotation, 222–223
@TransactionConfiguration, 226

transactionManager attribute, 217
UML sequence diagram, 212–213

Spring project, 1
certification exam, 3–4
core components, 3
development environment

build tool, 8–10
IDE, 10
JVM, 8
Pet Sitter, 11–12, 14–15

flash drive, 4
frameworks, 1
infrastructure beans, 1
Java application, 2
libraries, 1
nutshell, 3
objectives, 3

author information, 7
code downloads, 7
conventions, 7
list of, 5–6
modules, 6

use of, 5
web stack, 2

Spring Security, 298–300
chained filters, 303–304, 316
configuration, 301
Java Configuration, 313–317
method security, 321–325
security tag library, 317–320
XML configuration, 301–312

Spring Web, 271
App Configuration, 274–276
application, 291
controllers, 277–281
@MVC, 285–286
running application, 291–292
running with jetty, 292–293
running with Tomcat, 294–295, 297
steps to develop MVC

application, 276
XML, 281–285

Spring WebFlow, 271, 274
Spring Web MVC application, 344

��������� T

integration test, 117, 146
Mockito methods

Gradle test task, 148–149
Intellij IDEA, 148
pet-sitter project build, 150–151
web report, 149–150

Page 477



mock object
EasyMock, 125–127
jMock, 127–129
libraries and frameworks, 124
Mockito, 130–133
PowerMock, 133

Spring application
buildPet method, 136
configuration classes, 139
@ContextConfiguration annotation, 139
integration test, 136–137
Java Configuration classes, 138
mapping interface, 141
profiles, 144–146
repo dependency, 138–139
rules, 142
simplePetService, 134–135, 138
source code, 140
spring-test, 134
stereotype annotations, 138
test class, 143–144
test context, 142
TestObjectsBuilder method, 136

abstract class, 119–120
assert* methods, 124
delete methods, 123
JUnit components, 124
PetRepo methods, 120, 121
SimplePetService, 117–118
SimplePetServiceTest methods, 122–123

test-driven development, 115, 116
types of, 115
unit testing, 116–117, 147

Tomcat, 294–295, 297–299, 332, 334
Transaction management

configuration support, 214–215
declare transactional methods, 215–217
@EnableTransactionManagement, 215
explicit exception, 216
transactionManager attribute, 217

console log, 220–221
declarative model

clarification, 228
IDEA execution, 229
repository transactional bean, 231–232
service method, 228, 230
@Transactional service class, 229

distributed transaction, 233–234
isolation attribute, 221
manager framework, 213
nested transaction, 218–220
noRollbackFor attribute values, 222

operation, 214
programatic transaction model, 232–233
propagation attribute

NEVER, 218

readOnly attribute, 217
rollbackFor attribute values, 222
testing methods, 223–225

@BeforeTransaction, 226
defaultRollback attribute, 226
repository methods, 225
@Rollback annotation, 225
third-party implementation, 226–227
@TransactionConfiguration, 226

@Transactional annotation, 222–223
transactionManager attribute, 217
UML sequence diagram, 212–213

��������� U, V
Uniform Resource Locator (URL), 278
Unit testing, 116–117

��������� W
WebLogicJtaTransactionManager, 213
WebMvcConfigurerAdapter class, 288
Web services

description, 349, 382
designing and development, 383
Java Code with XJC, 386–387
and remoting, 349
and remotingfeatures, 382–383
and remotingXML, 382
SOAP messages, 382, 384–386
Spring Boot WS application, 387–390
testing, 392–395
WSDL, 391

Web Services Description Language (WSDL), 391
WSDL. See Web Services Description

Language (WSDL)

��������� X
XML, Spring Web, 281–285

��������� Y, Z
YAML, 338–340

Testing (cont.)

Similer Documents