Getting Started With Spring Framework J Sharma Ashish Sarin download https://ebookbell.com/product/getting-started-with-spring- framework-j-sharma-ashish-sarin-42536226 Explore and download more ebooks at ebookbell.com
Here are some recommended products that we believe you will be interested in. You can click the link to download. Getting Started With Roo Rapid Application Developent For Java And Spring 1st Edition Josh Long https://ebookbell.com/product/getting-started-with-roo-rapid- application-developent-for-java-and-spring-1st-edition-josh- long-23135206 Getting Started With Natural Language Processing Final Release 1st Edition Ekaterina Kochmar https://ebookbell.com/product/getting-started-with-natural-language- processing-final-release-1st-edition-ekaterina-kochmar-46078164 Getting Started With Uno Platform And Winui 3 Handson Building Of Crossplatform Desktop Mobile And Web Applications That Can Run Anywhere 1st Edition Andrew Hoefling https://ebookbell.com/product/getting-started-with-uno-platform-and- winui-3-handson-building-of-crossplatform-desktop-mobile-and-web- applications-that-can-run-anywhere-1st-edition-andrew- hoefling-46364362 Getting Started With Secure Embedded Systems Alexandru Radovici https://ebookbell.com/product/getting-started-with-secure-embedded- systems-alexandru-radovici-47255148
Getting Started With Visual Studio 2022 Learning And Implementing New Features 2nd Dirk Strauss https://ebookbell.com/product/getting-started-with-visual- studio-2022-learning-and-implementing-new-features-2nd-dirk- strauss-47378260 Getting Started With Microsoft Viva An End User Guide To Business Transformation 1st Edition Darce Hess https://ebookbell.com/product/getting-started-with-microsoft-viva-an- end-user-guide-to-business-transformation-1st-edition-darce- hess-47554262 Getting Started With Forex Trading Using Python Beginners Guide To The Currency Market And Development Of Trading Algorithms 1st Edition Alex Krishtop https://ebookbell.com/product/getting-started-with-forex-trading- using-python-beginners-guide-to-the-currency-market-and-development- of-trading-algorithms-1st-edition-alex-krishtop-48054962 Getting Started With Angular Create And Deploy Angular Applications 1st Edition Victorhugogarcia https://ebookbell.com/product/getting-started-with-angular-create-and- deploy-angular-applications-1st-edition-victorhugogarcia-48081270 Getting Started With Python Data Analysis Phuong Voth Martin Czygan https://ebookbell.com/product/getting-started-with-python-data- analysis-phuong-voth-martin-czygan-49052760
Getting started with Spring Framework Second Edition Ashish Sarin, J Sharma
Table of contents Preface How to use this book Conventions used in this book Feedback and questions About the authors Chapter 1 – Introduction to Spring Framework 1-1 Introduction 1-2 Spring Framework modules 1-3 Spring IoC container 1-4 Benefits of using Spring Framework Consistent approach to managing local and global transactions Declarative transaction management Security JMX (Java Management Extensions) JMS (Java Message Service) Caching 1-5 A simple Spring application Identifying application objects and their dependencies Creating POJO classes corresponding to identified application objects Creating the configuration metadata Creating an instance of Spring container Access beans from the Spring container 1-6 Frameworks built on top of Spring 1-7 Summary
Chapter 2 – Spring Framework basics 2-1 Introduction 2-2 Programming to interfaces design principle Scenario: Dependent class contains reference to the concrete class of dependency Scenario: Dependent class contains reference to the interface implemented by the dependency Spring’s support for ‘programming to interfaces’ design approach 2-3 Different approaches to instantiating Spring beans Instantiating beans via static factory methods Instantiating beans via instance factory methods 2-4 Dependency injection techniques Setter-based DI Constructor-based DI 2-5 Bean scopes Singleton Prototype Choosing the right scope for your beans 2-6 Summary Chapter 3 - Configuring beans 3-1 Introduction 3-2 Bean definition inheritance MyBank – Bean definition inheritance example What gets inherited ? 3-3 Constructor argument matching Passing simple values and bean references using <constructor-arg> element Constructor argument matching based on type Constructor argument matching based on name
3-4 Configuring different types of bean properties and constructor arguments Built-in property editors in Spring Specifying values for different collection types Specifying values for arrays Default collection implementation for <list>, <set> and <map> elements 3-5 Built-in property editors CustomCollectionEditor CustomMapEditor CustomDateEditor 3-6 Registering property editors with the Spring container Creating a PropertyEditorRegistrar implementation Configuring the CustomEditorConfigurer class 3-7 Concise bean definitions with p and c namespaces p-namespace c-namespace 3-8 Spring’s util schema <list> <map> <set> <properties> <constant> <property-path> 3-9 FactoryBean interface MyBank application – Storing events in the database MyBank – FactoryBean example Accessing the FactoryBean instance 3-10 Summary Chapter 4 - Dependency injection
4-1 Introduction 4-2 Inner beans 4-3 Explicitly controlling the bean initialization order with depends- on attribute MyBank – implied dependencies between beans Implicit dependency problem 4-4 Singleton- and prototype-scoped bean’s dependencies Singleton-scoped bean’s dependencies Prototype-scoped bean’s dependencies 4-5 Obtaining new instances of prototype beans inside singleton beans ApplicationContextAware interface <lookup-method> element <replaced-method> element 4-6 Autowiring dependencies byType constructor byName default / no Making beans unavailable for autowiring Autowiring limitations 4-7 Summary Chapter 5 - Customizing beans and bean definitions 5-1 Introduction 5-2 Customizing bean’s initialization and destruction logic Making Spring invoke cleanup method specified by the destory- method attribute Cleanup methods and prototype-scoped beans Specifying default bean initialization and destruction methods for all beans
InitializingBean and DisposableBean lifecycle interfaces JSR 250’s @PostConstruct and @PreDestroy annotations 5-3 Interacting with newly created bean instances using BeanPostProcessor BeanPostProcessor example – Validating bean instances BeanPostProcessor example – Resolving bean dependencies BeanPostProcessor behavior for FactoryBeans RequiredAnnotationBeanPostProcessor DestructionAwareBeanPostProcessor 5-4 Modifying bean definitions using BeanFactoryPostProcessor BeanFactoryPostProcessor example PropertySourcesPlaceholderConfigurer PropertyOverrideConfigurer 5-5 Summary Chapter 6- Annotation-driven development with Spring 6-1 Introduction 6-2 Identifying Spring components with @Component 6-3 @Autowired - autowiring dependencies by type 6-4 @Qualifier – autowiring dependencies by name 6-5 JSR 330’s @Inject and @Named annotations 6-6 JSR 250’s @Resource annotation 6-7 @Scope, @Lazy, @DependsOn and @Primary annotations 6-8 Simplifying component configuration using @Value annotation 6-9 Validating objects using Spring’s Validator interface 6-10 Specifying constraints using JSR 303 annotations JSR 303 support in Spring 6-11 Programmatically configuring Spring beans using @Configuration and @Bean annotations
6-12 Summary Chapter 7 - Database interaction using Spring 7-1 Introduction 7-2 MyBank application’s requirements 7-3 Developing the MyBank application using Spring’s JDBC module Configuring a data source Creating DAOs that use Spring’s JDBC module classes 7-4 Developing the MyBank application using Hibernate Configuring SessionFactory instance Creating DAOs that use Hibernate API for database interaction 7-5 Transaction management using Spring MyBank’s transaction management requirements Programmatic transaction management Declarative transaction management Spring’s support for JTA 7-6 Summary Chapter 8 - Messaging, emailing, asynchronous method execution, and caching using Spring 8-1 Introduction 8-2 MyBank application’s requirements 8-3 Sending JMS messages Configuring ActiveMQ broker to run in embedded mode Configuring a JMS ConnectionFactory Sending JMS messages using JmsTemplate Sending JMS messages within a transaction Dynamic JMS destinations and JmsTemplate configuration JmsTemplate and message conversion 8-4 Receiving JMS messages
Synchronously receiving JMS messages using JmsTemplate Asynchronously receiving JMS messages using message listener containers 8-5 Sending emails 8-6 Task scheduling and asynchronous execution TaskExecutor interface TaskScheduler interface @Async and @Scheduled annotations 8-7 Caching Configuring a CacheManager Caching annotations - @Cacheable, @CacheEvict and @CachePut 8-8 Running the MyBank application 8-9 Summary Chapter 9 - Aspect-oriented programming 9-1 Introduction 9-2 A simple AOP example 9-3 Spring AOP framework Proxy creation expose-proxy attribute 9-4 Pointcut expressions @Pointcut annotation execution and args pointcut designators bean pointcut designator Annotations-based pointcut designators 9-5 Advice types Before advice After returning advice After throwing advice After advice
Around advice 9-6 Spring AOP - XML schema-style Configuring an AOP aspect Configuring an advice Associating a pointcut expression with an advice 9-7 Summary Chapter 10 – Spring Web MVC basics 10-1 Introduction 10-2 Directory structure of sample web projects 10-3 Understanding the ‘Hello World’ web application HelloWorldController.java – Hello World web application’s controller class helloworld.jsp – JSP page that shows the ‘Hello World !!’ message myapp-config.xml – Web application context XML file web.xml – Web application deployment descriptor 10-4 DispatcherServlet – the front controller Accessing ServletContext and ServletConfig objects 10-5 Developing controllers using @Controller and @RequestMapping annotations Developing a ‘Hello World’ web application using an annotated controller 10-6 MyBank web application’s requirements 10-7 Spring Web MVC annotations - @RequestMapping and @RequestParam Mapping requests to controllers or controller methods using @RequestMapping @RequestMapping annotated methods arguments @RequestMapping annotated methods return types Passing request parameters to controller methods using @RequestParam
10-8 Validation 10-9 Handling exceptions using @ExceptionHandler annotation 10-11 Loading root web application context XML file(s) 10-12 Summary Chapter 11 – Validation and data binding in Spring Web MVC 11-1 Introduction 11-2 Adding and retrieving model attributes using @ModelAttribute annotation Adding model attributes using method-level @ModelAttribute annotation Retrieving model attributes using @ModelAttribute annotation Request processing and @ModelAttribute annotated methods Behavior of @ModelAttribute annotated method arguments RequestToViewNameTranslator 11-3 Caching model attributes using @SessionAttributes annotation 11-4 Data binding support in Spring WebDataBinder – data binder for web request parameters Configuring a WebDataBinder instance Allowing or disallowing fields from data binding process Inspecting data binding and validation errors using BindingResult object 11-5 Validation support in Spring Validating model attributes using Spring’s Validator interface Specifying constraints using JSR 303 annotations Validating objects that use JSR 303 annotations 11-6 Spring’s form tag library HTML5 support in Spring’s form tag library 11-7 Summary Chapter 12 –Developing RESTful web services using Spring Web
MVC 12-1 Introduction 12-2 Fixed deposit web service 12-3 Implementing a RESTful web service using Spring Web MVC JSON (JavaScript Object Notation) FixedDepositWS web service implementation 12-4 Accessing RESTful web services using RestTemplate 12-5 Converting Java objects to HTTP requests and responses and vice versa using HttpMessageConverter 12-6 @PathVariable and @MatrixVariable annotations 12-7 Summary Chapter 13 – More Spring Web MVC – internationalization, file upload and asynchronous request processing 13-1 Introduction 13-2 Pre- and post-processing requests using handler interceptors Implementing and configuring a handler interceptor 13-3 Internationalizing using resource bundles MyBank web application’s requirements Internationalizing and localizing MyBank web application 13-4 Asynchronously processing requests Asynchronous request processing configuration Returning Callable from @RequestMapping methods Returning DeferredResult from @RequestMapping methods Setting default timeout value Intercepting asynchronous requests 13-5 Type conversion and formatting support in Spring Creating a custom Converter Configuring and using a custom Converter Creating a custom Formatter
Configuring a custom Formatter Creating AnnotationFormatterFactory to format only @AmountFormat annotated fields Configuring AnnotationFormatterFactory implementation 13-6 File upload support in Spring Web MVC Uploading files using CommonsMultipartResolver Uploading files using StandardServletMultipartResolver 13-7 Summary Chapter 14 – Securing applications using Spring Security 14-1 Introduction 14-2 Security requirements of the MyBank web application 14-3 Securing MyBank web application using Spring Security Web request security configuration Authentication configuration Securing JSP content using Spring Security’s JSP tab library Securing methods 14-4 MyBank web application - securing FixedDepositDetails instances using Spring Security’s ACL module Deploying and using ch14-bankapp-db-security project Database tables to store ACL and user information User authentication Web request security JdbcMutableAclService configuration Method-level security configuration Domain object instance security Managing ACL entries programmatically MutableAcl and security 14-5 Summary Appendix A – Importing and deploying sample projects in Eclipse IDE (or IntelliJ IDEA)
A-1 Setting up the development environment A-2 Importing a sample project into Eclipse IDE (or IntelliJ IDEA) Importing a sample project Configuring the M2_REPO classpath variable in the Eclipse IDE A-3 Configuring Eclipse IDE with Tomcat 7 server A-4 Deploying a web project on Tomcat 7 server Running the Tomcat 7 server in embedded mode
Preface How to use this book Download sample projects This book comes with many sample projects that you can download from the following Google Code project: http://code.google.com/p/getting-started-with- spring-framework-2edition/. You can download the sample projects as a single ZIP file or you can checkout the sample projects using SVN. For more details, refer to the above URL. Import sample projects into your Eclipse or IntelliJ IDEA IDE If you see IMPORT chapter<chapter-number>/<project name> at any point while reading the book, you should import the specified project into your Eclipse or IntelliJ IDEA IDE (or any other IDE that you are using). The sample projects use Maven 3.x build tool for building the project; therefore, you’ll find a pom.xml file inside each of the projects. A pom.xml file is also provided at the root of the source code distribution, which builds all the projects. Refer appendix A to see the steps required for importing and running the sample projects. Refer to code examples Each example listing specifies the sample project name (using Project label) and the location of the source file (using Source location label). If the Project and Source location labels are not specified, you can assume that the code shown in the example listing is not being used anywhere in the sample projects, and it has been shown purely to simplify understanding. Conventions used in this book Italics has been used for emphasizing terms Comic Sans MS has been used for example listings, Java code, configuration details in XML and properties files Comic Sans MS has been used in example listings to highlight important parts of the code or configuration
A NOTE highlights an importaint point. Feedback and questions You can post your feedback and questions to the authors in the following Google Groups forum: https://groups.google.com/forum/#!forum/getting-started-with- spring-framework About the authors Ashish Sarin is a Sun Certified Enterprise Architect with more than 14 years of experience in architecting applications. He is the author of Spring Roo 1.1 Cookbook (by Packt Publishing) and Portlets in Action (by Manning Publications) J Sharma is a freelance Java developer with extensive experience in developing Spring applications.
Chapter 1 – Introduction to Spring Framework
1-1 Introduction In the traditional Java enterprise application development efforts, it was a developer’s responsibility to create well-structured, maintainable and easily testable applications. The developers used myriad design patterns to address these non-business requirements of an application. This not only led to low developer productivity, but also adversely affected the quality of developed applications. Spring Framework (or ‘Spring’ in short) is an open source application framework from SpringSource (http://www.springsource.org) that simplifies developing Java enterprise applications. It provides the infrastructure for developing well-structured, maintainable and easily testable applications. When using Spring Framework, a developer only needs to focus on writing the business logic of the application, resulting in improved developer productivity. You can use Spring Framework to develop standalone Java applications, web applications, applets, or any other type of Java application. This chapter starts off with an introduction to Spring Framework modules and its benefits. At the heart of Spring Framework is its Inversion of Control (IoC) container, which provides dependency injection (DI) feature. This chapter introduces Spring’s DI feature and IoC container, and shows how to develop a standalone Java application using Spring. Towards the end of this chapter, we’ll look at some of the SpringSource’s projects that use Spring Framework as their foundation. This chapter will set the stage for the remaining chapters that delve deeper into the Spring Framework. NOTE In this book, we’ll use an example Internet Banking application, MyBank, to introduce Spring Framework features.
1-2 Spring Framework modules Spring Framework consists of multiple modules that are grouped based on the application development features they address. The following table describes the different module groups in Spring Framework: Module group Description Core container Contains modules that form the foundation of Spring Framework. The modules in this group provide Spring’s DI feature and IoC container implementation. AOP and instrumentation Contains modules that support AOP (Aspect-oriented Programming) and class instrumentation. Data Access/Integration Contains modules that simplify interaction with databases and messaging providers. This module group also contains modules that support programmatic and declarative transaction management, and object/XML mapping implementations, like JAXB and Castor. Web Contains modules that simplify developing web and portlet applications. Test Contains a single module that simplifies creating unit and integration tests. The above table shows that Spring covers every aspect of enterprise application development; you can use Spring for developing web applications, accessing databases, managing transactions, creating unit and integration tests, and so on. The Spring Framework modules are designed in such a way that you only need to include the modules that your application needs. For instance, to use Spring’s DI feature in your application, you only need to include the modules grouped under Core container. As you progress through this book, you’ll find details of some of the modules that are part of Spring, and examples that show how they are used in developing applications. The following figure shows the inter-dependencies of different modules of Spring:
Figure 1-1 Spring modules inter-dependencies You can infer from the above figure that the modules contained in the Core container group are central to the Spring Framework, and other modules depend on it. Equally important are the modules contained in the AOP and instrumentation group because they provide AOP features to other modules in the Spring Framework. Now, that you have some basic idea about the areas of application development covered by Spring, let’s look at the Spring IoC container.
1-3 Spring IoC container A Java application consists of objects that interact with each other to provide application behavior. The objects with which an object interacts are referred to as its dependencies. For instance, if an object X interacts with objects Y and Z, then Y and Z are dependencies of object X. DI is a design pattern in which the dependencies of an object are typically specified as arguments to its constructor and setter methods. And, these dependencies are injected into the object when it’s created. In a Spring application, Spring IoC container (also referred to as Spring container) is responsible for creating application objects and injecting their dependencies. The application objects that the Spring container creates and manages are referred as beans. As the Spring container is responsible for putting together application objects, you don’t need to implement design patterns, like Factory, Service Locator, and so on, to compose your application. DI is also referred to as Inversion of Control (IoC) because the responsibility of creating and injecting dependencies is not with the application object but with the Spring container. Let’s say that the MyBank application (which is the name of our sample application) contains two objects, FixedDepositController and FixedDepositService. The following example listing shows that the FixedDepositController object depends on FixedDepositService object: Example listing 1-1: FixedDepositController class public class FixedDepositController { private FixedDepositService fixedDepositService; public FixedDepositController() { fixedDepositService = new FixedDepositService(); } public boolean submit() { //-- save the fixed deposit details fixedDepositService.save(.....); }
} In the above example listing, FixedDepositController’s constructor creates an instance of FixedDepositService which is later used in FixedDepositController’s submit method. As FixedDepositController interacts with FixedDepositService, FixedDepositService represents a dependency of FixedDepositController. To configure FixedDepositController as a Spring bean, you first need to modify the FixedDepositController class of example listing 1-1 such that it accepts FixedDepositService dependency as a constructor argument or as a setter method argument. The following example listing shows the modified FixedDepositController class: Example listing 1-2: FixedDepositController class – FixedDepositService is passed as a constructor argument public class FixedDepositController { private FixedDepositService fixedDepositService; public FixedDepositController(FixedDepositService fixedDepositService) { this.fixedDepositService = fixedDepositService; } public boolean submit() { //-- save the fixed deposit details fixedDepositService.save(.....); } } The above example listing shows that the FixedDepositService instance is now passed as a constructor argument to the FixedDepositController instance. Now, the FixedDepositService class can be configured as a Spring bean. Notice that the FixedDepositController class doesn’t implement or extend from any Spring interface or class. For a given application, information about application objects and their dependencies is specified using configuration metadata. Spring IoC container reads application’s configuration metadata to instantiate application objects and inject their dependencies. The following example listing shows the configuration metadata (in XML format) for an application that consists of MyController and
MyService classes: Example listing 1-3: Configuration metadata <beans .....> <bean id="myController" class="sample.spring.controller.MyController"> <constructor-arg index="0" ref="myService" /> </bean> <bean id="myService" class="sample.spring.service.MyService"/> </beans> In the above example listing, each <bean> element defines an application object that is managed by the Spring container, and the <constructor-arg> element specifies that an instance of MyService is passed as an argument to MyController’s constructor. The <bean> element is discussed in detail later in this chapter, and the <constructor-arg> element is discussed in chapter 2. Spring container reads the configuration metadata (like the one shown in example listing 1-3) of an application and creates the application objects defined by <bean> elements and injects their dependencies. Spring container makes use of Java Reflection API (http://docs.oracle.com/javase/tutorial/reflect/index.html) to create application objects and inject their dependencies. The following figure summarizes how the Spring container works: Figure 1-2 Spring container reads application’s configuration metadata and creates a fully-configured application
The configuration metadata can be supplied to the Spring container via XML (as shown in example listing 1-3), Java annotations (refer chapter 6) and also through the Java code (refer chapter 6). As the Spring container is responsible for creating and managing application objects, enterprise services (like transaction management, security, remote access, and so on) can be transparently applied to the objects by the Spring container. The ability of the Spring container to enhance the application objects with additional functionality makes it possible for you to model your application objects as simple Java objects (also referred to as POJOs or Plain Old Java Objects). Java classes corresponding to POJOs are referred to as POJO classes, which are nothing but Java classes that don’t implement or extend framework- specific interfaces or classes. The enterprise services, like transaction management, security, remote access, and so on, required by these POJOs are transparently provided by the Spring container. Now, that we know how Spring container works, let’s look at some examples that demonstrate benefits of developing applications using Spring.
1-4 Benefits of using Spring Framework In the previous section, we discussed the following benefits of using Spring: § Spring simplifies composing Java applications by taking care of creating application objects and injecting their dependencies § Spring promotes developing applications as POJOs Spring also simplifies interaction with JMS providers, JNDI, MBean servers, email servers, databases, and so on, by providing a layer of abstraction that takes care of the boilerplate code. Let’s take a quick look at a few examples to better understand the benefits of developing applications using Spring. Consistent approach to managing local and global transactions If you are using Spring for developing transactional applications, you can use Spring’s declarative transaction management support to manage transactions. The following example listing shows the FixedDepositService class of MyBank application: Example listing 1-4 – FixedDepositService class public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } The FixedDepositService class is a POJO class that defines methods to create and retrieve details of fixed deposits. The following figure shows the form for creating a new fixed deposit:
Figure 1-3 HTML form for creating a new fixed deposit A customer enters the fixed deposit amount, tenure and email id information in the above form and clicks the Save button to create a new fixed deposit. The FixedDepositService’s createFixedDeposit method (refer example listing 1-1) is invoked to create the fixed deposit. The createFixedDeposit method debits the amount entered by the customer from his bank account, and creates a fixed deposit of the same amount. Let’s say that information about the bank balance of customers is stored in BANK_ACCOUNT_DETAILS database table, and the fixed deposit details are stored in FIXED_DEPOSIT_DETAILS database table. If a customer creates a fixed deposit of amount x, amount x is subtracted from the BANK_ACCOUNT_DETAILS table, and a new record is inserted in FIXED_DEPOSIT_DETAILS table to reflect the newly created fixed deposit. If BANK_ACCOUNT_DETAILS table is not updated or a new record is not inserted in FIXED_DEPOSIT_DETAILS table, it’ll leave the system in an inconsistent state. This means the createFixedDeposit method must be executed within a transaction. The database used by the MyBank application represents a transactional resource. In the traditional approach to perform a set of database modifications as a single unit of work, you’ll first disable auto-commit mode of JDBC connection, then execute SQL statements, and finally commit (or rollback) the transaction. The following example listing shows how to manage database transactions in the createFixedDeposit method using the traditional approach: Example listing 1-5 – Programmatically managing database transaction using JDBC Connection object
import java.sql.Connection; import java.sql.SQLException; public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { Connection con = ..... ; try { con.setAutoCommit(false); //-- execute SQL statements that modify database tables con.commit(); } catch(SQLException sqle) { if(con != null) { con.rollback(); } } ..... } } The above example listing shows that the createFixedDeposit method programmatically manages database transaction using JDBC Connection object. This approach is suitable for application scenarios in which a single database is involved. Transactions that are resource-specific, like the transaction associated with a JDBC Connection, are referred to as local transactions. When multiple transactional resources are involved, JTA (Java Transaction API) is used for managing transactions. For instance, if you want to send a JMS message to a messaging middleware (a transactional resource) and update a database (another transactional resource) in the same transaction, you must use a JTA transaction manager to manage transactions. JTA transactions are also referred to as global (or distributed) transactions. To use JTA, you fetch UserTransaction object (which is part of JTA API) from JNDI and programmatically start and commit (or rollback) transactions. As you can see, you can either use JDBC Connection (for local transactions) or
UserTransaction (for global transactions) object to programmatically manage transactions. It is important to note that a local transaction cannot run within a global transaction. This means that if you want database updates in createFixedDeposit method (refer example listing 1-5) to be part of a JTA transaction, you need to modify the createFixedDeposit method to use the UserTransaction object for transaction management. Spring simplifies transaction management by providing a layer of abstraction that gives a consistent approach to managing both local and global transactions. This means that if you write the createFixedDeposit method (refer example listing 1-5) using Spring’s transaction abstraction, you don’t need to modify the method when you switch from local to global transaction management, or vice versa. Spring’s transaction abstraction is explained in chapter 7. Declarative transaction management Spring gives you the option to use declarative transaction management. You can annotate a method with Spring’s @Transactional annotation and let Spring handle transactions, as shown here: Example listing 1-6 – @Transactional annotation usage import org.springframework.transaction.annotation.Transactional; public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } @Transactional public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } The above example listing shows that the FixedDepositService class doesn’t implement or extend from any Spring-specific interface or class to use Spring’s transaction management facility. The Spring Framework transparently provides transaction management feature to @Transactional annotated createFixedDeposit method. This shows that Spring is a non-invasive framework because it doesn’t require your application objects to be dependent upon Spring- specific classes or interfaces. Also, you don’t need to directly work with
transaction management APIs to manage transactions. Security Security is an important aspect of any Java application. Spring Security (http://static.springsource.org/spring-security/site/) is a SpringSource’s project that is built on top of Spring Framework. Spring Security provides authentication and authorization features that you can use for securing Java applications. Let’s say that the following 3 user roles have been identified for the MyBank application: LOAN_CUSTOMER, SAVINGS_ACCOUNT_CUSTOMER and APPLICATION_ADMIN. A customer must be associated with the SAVINGS_ACCOUNT_CUSTOMER or the APPLICATION_ADMIN role to invoke the createFixedDeposit method of FixedDepositService class (refer example listing 1-6). Using Spring Security you can easily address this requirement by annotating createFixedDeposit method with Spring Security’s @Secured annotation, as shown in the following example listing: Example listing 1-7 – Secured createFixedDeposit method import org.springframework.transaction.annotation.Transactional; import org.springframework.security.access.annotation.Secured; public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } @Transactional @Secured({ "SAVINGS_ACCOUNT_CUSTOMER", "APPLICATION_ADMIN" }) public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } If you annotate a method with Spring Security’s @Secured annotation, security feature is transparently applied to the method by the Spring Security framework. The above example listing shows that for implementing method-level security you don’t need to extend or implement any Spring-specific classes or interfaces. Also, you don’t need to write security-related code in your business methods.
Spring Security framework is discussed in detail in chapter 14. JMX (Java Management Extensions) Spring’s JMX support simplifies incorporating JMX technology in your applications. Let’s say that the fixed deposit facility of MyBank application should only be available to customers from 9:00 AM to 6:00 PM everyday. To address this requirement, a variable is added to the FixedDepositService class, which acts as a flag indicating whether the fixed deposit service is active or inactive. The following example listing shows the FixedDepositService class that uses such a flag: Example listing 1-8 – FixedDepositService with active variable public class FixedDepositService { private boolean active; public FixedDepositDetails getFixedDepositDetails( ..... ) { if(active) { ..... } } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { if(active) { ..... } } public void activateService() { active = true; } public void deactivateService() { active = false; } } The above example listing shows that a variable named active is added to the FixedDepositService class. If the value of the active variable is true, the getFixedDepositDetails and createFixedDeposit methods work as expected. If the value of the active variable is false, the getFixedDepositDetails and createFixedDeposit methods throw an exception indicating that the fixed deposit service is currently inactive. The activateService and deactivateService methods
set the value of active variable to true and false, respectively. Now, who calls the activateService and deactivateService methods? Let’s say a separate scheduler application, Bank App Scheduler, runs at 9:00 AM and 6:00 PM to execute activateService and deactivateService methods, respectively. The Bank App Scheduler application uses JMX (Java Management Extensions) API to remotely interact with FixedDepositService instance. NOTE Refer to the following article to learn more about JMX: http://docs.oracle.com/javase/tutorial/jmx/index.html. As Bank App Scheduler uses JMX to change the value of the active variable of the FixedDepositService instance, you need to register the FixedDepositService instance as a managed bean (or MBean) with an MBean server, and expose FixedDepositService’s activateService and deactivateService methods as JMX operations. In Spring, you register instances of a class with the MBean server by annotating the class with Spring’s @ManagedResource annotation, and expose the methods of the class as JMX operations using Spring’s @ManagedOperation annotation. The following example listing shows usage of @ManagedResource and @ManagedOperation annotations to register instances of the FixedDepositService class with the MBean server, and to expose its activateService and deactivateService methods as JMX operations: Example listing 1-9 – FixedDepositService class that uses Spring’s JMX support import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; @ManagedResource(objectName = "fixed_deposit_service:name=FixedDepositService") public class FixedDepositService { private boolean active; public FixedDepositDetails getFixedDepositDetails( ..... ) { if(active) { ..... } } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails)
{ if(active) { ..... } } @ManagedOperation public void activateService() { active = true; } @ManagedOperation public void deactivateService() { active = false; } } The above example listing shows that the FixedDepositService class doesn’t directly use JMX API to register its instances with the MBean server and to expose its methods as JMX operations. JMS (Java Message Service) Spring’s JMS support simplifies sending and receiving messages from JMS providers. In MyBank application, when a customer submits a request to receive details of their fixed deposits via email, the FixedDepositService sends the request details to a JMS messaging middleware (like ActiveMQ). The request is later processed by a message listener. Spring simplifies interaction with JMS providers by providing a layer of abstraction. The following example listing shows how FixedDepositService class sends request details to a JMS provider using Spring’s JmsTemplate: Example listing 1-10 – FixedDepositService that sends JMS messages import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; public class FixedDepositService { @Autowired
private transient JmsTemplate jmsTemplate; ..... public boolean submitRequest(Request request) { jmsTemplate.convertAndSend(request); } } The above example listing shows that the FixedDepositService defines a variable of type JmsTemplate, and is annotated with Spring’s @Autowired annotation. For now, you can assume that the @Autowired annotation provides access to a JmsTemplate instance. The JmsTemplate instance knows about the JMS destination to which the JMS message is to be sent. How the JmsTemplate is configured is described in detail in chapter 8. The FixedDepositService’s submitRequest method invokes JmsTemplate’s convertAndSend method to send request details (represented by Request argument of submitRequest method) as a JMS message to the JMS provider. Once again, the above example listing shows that if you are using Spring Framework to send messages to JMS providers, then you don’t need to directly deal with JMS API. Caching Spring’s cache abstraction provides a consistent approach to use caching in your application. It’s common to use caching solutions to improve the performance of an application. MyBank application uses a caching product to improve the performance of read operations for fixed deposit details. Spring Framework simplifies interacting with different caching solutions by abstracting caching- related logic. The following example listing shows that the FixedDepositService’s getFixedDepositDetails method uses Spring’s cache abstraction feature to cache fixed deposit details: Example listing 1-11 – FixedDepositService that caches fixed deposit details import org.springframework.cache.annotation.Cacheable; public class FixedDepositService {
@Cacheable("FixedDeposits") public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } In the above example listing, Spring’s @Cacheable annotation indicates that the fixed deposit details returned by the getFixedDepositDetails method are cached. If the getFixedDepositDetails method is invoked with the same argument value(s), the getFixedDepositDetails method is not executed, and the fixed deposit details are returned from the cache. This shows that if you are using Spring Framework you don’t need to write caching-related logic in your classes. Spring’s cache abstraction is explained in detail in chapter 8. In this section, we saw that Spring Framework simplifies developing enterprise applications by transparently providing services to POJOs, thereby shielding developers from lower level API details. Spring also provides easy integration with standard frameworks, like Hibernate, iBATIS, Quartz, JSF, Struts, EJB, and so on, which makes Spring an ideal choice for enterprise application development. Now, that we have looked at some of the benefits of using Spring Framework, let’s take a look at how to develop a simple Spring application.
1-5 A simple Spring application In this section, we’ll look at a simple Spring application that uses Spring’s DI feature. To use Spring’s DI feature in an application, follow these steps: 1. identify application objects and their dependencies 2. create POJO classes corresponding to the application objects identified in step 1 3. create configuration metadata that depicts application objects and their dependencies 4. create an instance of Spring IoC container and pass the configuration metadata to it 5. access application objects from the Spring IoC container instance Let’s now look at above mentioned steps in the context of MyBank application. Identifying application objects and their dependencies We discussed earlier that the MyBank application shows a form for creating a fixed deposit (refer figure 1-3) to its users for creating a fixed deposit. The following sequence diagram shows the application objects (and their interaction) that come into picture when the user submits the form: Figure 1-4 MyBank’s application objects and their dependencies In the above sequence diagram, FixedDepositController represents a web controller that receives the request when the form is submitted. The fixed deposit
details are contained in the FixedDepositDetails object. The FixedDepositController invokes the createFixedDeposit method of FixedDepositService (a service layer object). Then, FixedDepositService invokes FixedDepositDao object (a data access object) to save the fixed deposit details in the application’s data store. So, we can interpret from the above diagram that FixedDepositService is a dependency of FixedDepositController object, and FixedDepositDao is a dependency of FixedDepositService object. IMPORT chapter 1/ch01-bankapp-xml (This project shows a simple Spring application that uses Spring’s DI feature. To run the application, execute the main method of the MyBankApp class of this project) Creating POJO classes corresponding to identified application objects Once you have identified application objects, the next step is to create POJO classes corresponding to these application objects. POJO classes corresponding to the FixedDepositController, FixedDepositService and FixedDepositDao application objects are available in ch01-bankapp-xml project. The ch01- bankapp-xml project represents a simplified version of MyBank application that uses Spring’s DI feature. You should import the ch01-bankapp-xml project into your IDE as in the remaining steps we’ll be looking at the files contained in this project. In section 1-3 we discussed that a dependency is passed to an application object as a constructor argument or as a setter method argument. The following code listing shows that an instance of FixedDepositService (a dependency of FixedDepositController) is passed as a setter method argument to the FixedDepositController object: Example listing 1-12 – FixedDepositController class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; ..... public class FixedDepositController { ..... private FixedDepositService fixedDepositService;
..... public void setFixedDepositService(FixedDepositService fixedDepositService) { logger.info("Setting fixedDepositService property"); this.fixedDepositService = fixedDepositService; } ..... public void submit() { fixedDepositService.createFixedDeposit(new FixedDepositDetails( 1, 10000, 365, "someemail@something.com")); } ..... } In the above example listing, FixedDepositService dependency is passed to FixedDepositController through setFixedDepositService method. We’ll soon see that the setFixedDepositService setter method is invoked by Spring. NOTE If you look at the FixedDepositController, FixedDepositService and FixedDepositDao classes, you’ll notice that none of these classes implement any Spring-specific interface or extend from any Spring-specific class. Let’s now look at how application objects and their dependencies are specified in the configuration metadata. Creating the configuration metadata We saw in section 1-3 that the configuration metadata specifies application objects and their dependencies, which is read by the Spring container to instantiate application objects and inject their dependencies. In this section, we’ll first look at what other information is contained in the configuration metadata, followed by an in-depth look at how configuration metadata is specified in XML format. The configuration metadata specifies information about the enterprise services (like transaction management, security and remote access) that are required by the application. For instance, if you want Spring to manage transactions, you need to configure an implementation of Spring’s PlatformTransactionManager interface in the configuration metadata. The PlatformTransactionManager
implementation is responsible for managing transactions (refer chapter 7 to know more about Spring’s transaction management feature). If your application interacts with messaging middlewares (like ActiveMQ), databases (like MySQL), e-mail servers, and so on, then Spring-specific objects that simplify interacting with these external systems are also defined in the configuration metadata. For instance, if your application sends or receives JMS messages from ActiveMQ, then you can configure Spring’s JmsTemplate class in the configuration metadata to simplify interaction with ActiveMQ. We saw in example listing 1-10 that if you use JmsTemplate for sending messages to a JMS provider, then you don’t need to deal with lower-level JMS API (refer chapter 8 to know more about Spring’s support for interacting with JMS providers). You can supply the configuration metadata to the Spring container via an XML file or through annotations in POJO classes. Starting with Spring 3.0, you can also supply the configuration metadata to the Spring container through Java classes annotated with Spring’s @Configuration annotation. In this section, we’ll see how configuration metadata is specified in XML format. In chapter 6, we’ll see how configuration metadata is supplied via annotations in POJO classes and through @Configuration annotated Java classes. You provide the configuration metadata for an application in XML format by creating an application context XML file that contains information about the application objects and their dependencies. Example listing 1-3 showed how an application context XML file looks like. The following XML shows the application context XML file of MyBank application that consists of FixedDepositController, FixedDepositService and FixedDepositDao objects (refer figure 1-4 to see how these objects interact with each other): Example listing 1-13 – applicationContext.xml - MyBank’s application context XML file Project – ch01-bankapp-xml Source location - src/main/resources/META-INF/spring <?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="controller" class="sample.spring.chapter01.bankapp.FixedDepositController"> <property name="fixedDepositService" ref="service" /> </bean> <bean id="service" class="sample.spring.chapter01.bankapp.FixedDepositService"> <property name="fixedDepositDao" ref="dao" /> </bean> <bean id="dao" class="sample.spring.chapter01.bankapp.FixedDepositDao"/> </beans> The following are the important points to note about the application context XML file shown above: · The <beans> element is the root element of the application context XML file, and is defined in spring-beans-4.0.xsd schema (also referred to as Spring’s beans schema). The spring-beans-4.0.xsd schema is contained in spring-beans-4.0.0.RELEASE.jar JAR file that comes with the Spring Framework distribution. · Each <bean> element configures an application object that is managed by the Spring container. In Spring Framework’s terminology, a <bean> element represents a bean definition. The object that the Spring container creates based on the bean definition is referred to as a bean. The id attribute specifies a unique name for the bean, and the class attribute specifies the fully-qualified class name of the bean. You can also use the name attribute of <bean> element to specify aliases for the bean. In MyBank application, the application objects are FixedDepositController, FixedDepositService and FixedDepositDao; therefore, we have 3 <bean> elements - one for each application object. As application objects configured by <bean> elements are managed by the Spring container, the responsibility for creating them and injecting their dependencies is with the Spring container. Instead of directly creating instances of application objects defined by <bean> elements, you should obtain them from the
Spring container. Later in this section, we’ll look at how to obtain application objects managed by Spring container. · No <bean> element is defined corresponding to the FixedDepositDetails domain object of MyBank application. This is because domain objects are not typically managed by the Spring container; they are created by the ORM framework (like Hibernate) used by the application, or you create them programmatically using the new operator. · The <property> element specifies a dependency (or a configuration property) of the bean configured by the <bean> element. The <property> element corresponds to a JavaBean-style setter method in the bean class which is invoked by the Spring container to set a dependency (or a configuration property) of the bean. Let’s now look at how dependencies are injected via setter methods. Injecting dependencies via setter methods To understand how dependencies are injected via setter methods defined in the bean class, let’s once again look at the FixedDepositController class of MyBank application: Example listing 1-14 – FixedDepositController class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; import org.apache.log4j.Logger; public class FixedDepositController { private static Logger logger = Logger.getLogger(FixedDepositController.class); private FixedDepositService fixedDepositService; public FixedDepositController() { logger.info("initializing");
} public void setFixedDepositService(FixedDepositService fixedDepositService) { logger.info("Setting fixedDepositService property"); this.fixedDepositService = fixedDepositService; } ..... } The above example listing shows that the FixedDepositController class declares an instance variable named fixedDepositService of type FixedDepositService. The fixedDepositService variable is set by the setFixedDepositService method - a JavaBean-style setter method for fixedDepositService variable. This is an example of setter-based DI, wherein a setter method satisfies a dependency. The following figure describes the bean definition for the FixedDepositController class in the applicationContext.xml file (refer example listing 1-13): Figure 1-5 Defining dependencies using <property> elements The above bean definition shows that the FixedDepositController bean defines its dependence on FixedDepositService bean via <property> element. The <property> element’s name attribute corresponds to the JavaBean-style setter method in the bean class that is invoked by the Spring container at the time of bean creation. The <property> element’s ref attribute identifies the Spring bean whose instance needs to be created and passed to the JavaBean-style setter
method. The value of ref attribute must match the id attribute’s value (or one of the names specified by the name attribute) of a <bean> element in the configuration metadata. In figure 1-5, the value of <property> element’s name attribute is fixedDepositService, which means that the <property> element corresponds to the setFixedDepositService setter method of FixedDepositController class (refer example listing 1-14). As the value of <property> element’s ref attribute is service, the <property> element refers to the <bean> element whose id attribute’s value is service. Now, the <bean> element whose id attribute’s value is service is the FixedDepositService bean (refer example listing 1-13). Spring container creates an instance of FixedDepositService class (a dependency), and invokes the setFixedDepositService method (a JavaBean-style setter method for fixedDepositService variable) of FixedDepositController (a dependent object), passing the FixedDepositService instance. In the context of FixedDepositController application object, the following figure summarizes the purpose of name and ref attributes of <property> element: Figure 1-6 <property> element’s name attribute corresponds to a JavaBean-style setter method that satisfies a bean dependency, and ref attribute refers to another
bean. The above figure shows that fixedDepositService value of name attribute corresponds to the setFixedDepositService method of FixedDepositController class, and service value of ref attribute refers to the bean whose id is service. NOTE It is fairly common to refer to a bean definition by its name (which is id attribute’s value) or type (which is class attribute’s value) or the interface implemented by the bean class. For instance, you can refer to ‘FixedDepositController bean’ as ‘controller bean’. And, if the FixedDepositController class implements FixedDepositControllerIntf interface, you can refer to ‘FixedDepositController bean’ as ‘FixedDepositControllerIntf bean’. The following diagram summarizes how the Spring container creates beans and injects their dependencies based on the configuration metadata supplied by the applicationContext.xml file (refer example listing 1-13) of MyBank application: Figure 1-7 - The sequence in which Spring IoC container creates beans and injects their dependencies. The above figure shows the sequence of steps followed by the Spring IoC container to create FixedDepositController, FixedDepositService and FixedDepositDao beans and inject their dependencies. Before attempting to create beans, the Spring container reads and validates the configuration metadata supplied by the applicationContext.xml file. The order in which the beans are
created by the Spring container depends on the order in which they are defined in the applicationContext.xml file. Spring container ensures that the dependencies of a bean are completely configured before the setter method is invoked. For example, the FixedDepositController bean is dependent on FixedDepositService bean; therefore, Spring container configures the FixedDepositService bean before invoking the setFixedDepositService method of FixedDepositController bean. The bean definitions that we have seen so far, instruct Spring container to create bean instances by invoking the no-argument constructor of the bean class, and inject dependencies using setter-based DI. In chapter 2, we’ll look at bean definitions that instruct Spring container to create a bean instance via a factory method defined in a class. Also, we’ll look at how to inject dependencies through constructor arguments (referred to as constructor-based DI), through arguments to the factory method that creates the bean instance, and by using setter-based DI on the bean instance returned by the factory method. Let’s now look at how to create an instance of Spring container and pass configuration metadata to it. Creating an instance of Spring container Spring’s ApplicationContext object represents an instance of Spring container. Spring provides a few built-in implementations of ApplicationContext interface, like ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, XmlWebApplicationContext, XmlPortletApplicationContext, and so on. The choice of the ApplicationContext implementation depends on how you have defined the configuration metadata (using XML, annotations or Java code), and the type of your application (standalone, web or portlet application). For instance, ClassPathXmlApplicationContext and FileSystemXmlApplicationContext classes are suitable for standalone applications in which configuration metadata is supplied in XML format, XmlWebApplicationContext is suitable for web applications in which the configuration metadata is supplied in XML format, AnnotationConfigWebApplicationContext is suitable for web applications in which configuration metadata is supplied through Java code, and so on. As MyBank application represents a standalone application, we can use either ClassPathXmlApplicationContext or FileSystemXmlApplicationContext class to
create an instance of Spring container. You should note that the ClassPathXmlApplicationContext class loads an application context XML file from the specified classpath location, and the FileSystemXmlApplicationContext class loads an application context XML file from the specified location on the filesystem. The following BankApp class of MyBank application shows that an instance of Spring container is created using the ClassPathXmlApplicationContext class: Example listing 1-15 – BankApp class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class BankApp { ..... public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/applicationContext.xml"); ..... } } The above example listing shows the BankApp’s main method, which is responsible for bootstrapping the Spring container. The classpath location of the application context XML file is passed to the constructor of ClassPathXmlApplicationContext class. The creation of ClassPathXmlApplicationContext instance results in creation of those beans in the application context XML file that are singleton-scoped and set to be pre- instantiated. In chapter 2, we’ll discuss bean scopes, and what it means to have beans pre- or lazily-instantiated by Spring container. For now, you can assume that the beans defined in the applicationContext.xml file of MyBank application are singleton-scoped and set to be pre-instantiated. This means that the beans
defined in the applicationContext.xml file are created when an instance of ClassPathXmlApplicationContext is created. Now, that we have seen how to create an instance of the Spring container, let’s look at how to retrieve bean instances from the Spring container. Access beans from the Spring container The application objects defined via <bean> elements are created and managed by the Spring container. You can access instances of these application objects by calling one of the getBean methods of the ApplicationContext interface. The following example listing shows the main method of BankApp class that retrieves an instance of FixedDepositController bean from the Spring container and invokes its methods: Example listing 1-16 – BankApp class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; import org.apache.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class BankApp { private static Logger logger = Logger.getLogger(BankApp.class); public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/applicationContext.xml"); FixedDepositController fixedDepositController = (FixedDepositController) context.getBean("controller"); logger.info("Submission status of fixed deposit : " + fixedDepositController.submit()); logger.info("Returned fixed deposit info : " + fixedDepositController.get());
} } At first, the ApplicationContext’s getBean method is invoked to retrieve an instance of FixedDepositController bean from the Spring container, followed by invocation of submit and get methods of FixedDepositController bean. The argument passed to the getBean method is the name of the bean whose instance you want to retrieve from the Spring container. The name of the bean passed to the getBean method must be the value of the id or name attribute of the bean that you want to retrieve. If no bean with the specified name is registered with the Spring container, an exception is thrown by the getBean method. In example listing 1-16, to configure the FixedDepositController instance, we didn’t programmatically create an instance of FixedDepositService and set it on the FixedDepositController instance. Also, we didn’t create an instance of FixedDepositDao and set it on the FixedDepositService instance. This is because the task of creating dependencies, and injecting them into the the dependent objects is handled by the Spring container. If you go to ch01-bankapp-xml project and execute the main method of BankApp class, you’ll see the following output on the console: INFO sample.spring.chapter01.bankapp.FixedDepositController - initializing INFO sample.spring.chapter01.bankapp.FixedDepositService - initializing INFO sample.spring.chapter01.bankapp.FixedDepositDao - initializing INFO sample.spring.chapter01.bankapp.FixedDepositService - Setting fixedDepositDao property INFO sample.spring.chapter01.bankapp.FixedDepositController - Setting fixedDepositService property INFO sample.spring.chapter01.bankapp.BankApp - Submission status of fixed deposit : true INFO sample.spring.chapter01.bankapp.BankApp - Returned fixed deposit info : id :1, deposit amount : 10000.0, tenure : 365, email : someemail@something.com The above output shows that Spring container creates an instance of each of the beans defined in the applicationContext.xml file of MyBank application. Also, Spring container uses setter-based DI to inject an instance of FixedDepositService into FixedDepositController instance, and an instance of FixedDepositDao into the FixedDepositService instance. Let’s now look at some of the frameworks that are built on top of Spring Framework.
1-6 Frameworks built on top of Spring Though there are many frameworks from SpringSource that use Spring Framework as the foundation, we’ll look at some of the widely popular ones. For a more comprehensive list of frameworks, and for more details about an individual framework, it’s recommended that you visit the SpringSource website (www.springsource.org). The following table provides a high-level overview of the frameworks from SpringSource that are built on top of Spring Framework: Framework Description Spring Security Authentication and authorization framework for enterprise applications. You need to configure a few beans in your application context XML file to incorporate authentication and authorization features into your application. Spring Data Provides a consistent programming model to interact with different types of databases. For instance, you can use it to interact with non-relational databases, like MongoDB or Neo4j, and you can also use it for accessing relational databases using JPA. Spring Batch If your application requires bulk processing, this framework is for you. Spring Integration Provides Enterprise Application Integration (EAI) capabilities to applications. Spring Social If your application requires interaction with social media websites, like Facebook and Twitter, then you’ll find this framework highly useful. Spring BlazeDS Integration If you are developing an Adobe Flex based application, you can use this framework to connect Flex frontend with Spring-based business tier. As the frameworks mentioned in the above table are built on top of Spring Framework, before using any of these frameworks make sure that they are compatible with the Spring Framework version that you are using.
1-7 Summary In this chapter, we looked at the benefits of using Spring Framework. We also looked at a simple Spring application that showed how to specify configuration metadata in XML format, create the Spring container instance and retrieve beans from it. In the next chapter, we’ll look at some of the foundation concepts of Spring Framework.
Chapter 2 – Spring Framework basics
Another Random Document on Scribd Without Any Related Topics
miracles occurred, that its later opponents should have given up this strong line of defence, and have adopted the far weaker one that they did occur, but were due to magic. We are quite justified, then, in saying that Christ's miracles were not disputed at the time, and considering their alleged publicity, this is a strong additional argument in their favour. [360] Origen cont. Cels., i. 38; ii. 48. (4.) The silence of classical writers. All that can be said on the other side is from the silence of classical writers. Had the miracles really occurred, it is said, especially in such a well-known place as Palestine, the writers of the day would have been full of them. Yet, with the single exception of Tacitus, they do not even allude to Christianity; and he dismisses it with contempt as a pernicious superstition.[361] [361] Tacitus Annals. Bk. xv., ch. 44. Now these words of Tacitus show that he had never studied the subject, for whatever may be said against the religion, it certainly was not pernicious; so he must have rejected Christianity without examination. And if the other classical writers did the same, there is nothing remarkable in their not alluding to it. Alleged marvels were common enough in those days, and they probably did not think the Christian miracles worth inquiring about. But we do not know of any writer who did inquire about them, and was not convinced of their truth. It may, of course, be replied that some of the events ought anyhow to be alluded to, such as the darkness over all the land at the time of the Crucifixion. And if this extended over the whole of Palestine, it is certainly strange that it should not be noticed. But it may only refer to the neighbourhood of Jerusalem. Compare the expression all the country of Judæa[362] (when referring to the people being baptized) which is evidently not meant to be taken literally. And if the darkness was limited to the neighbourhood of Jerusalem, there
is nothing surprising in its not being recorded by any except Christians, for whom of course it had a special significance. [362] Mark 1. 5. It should also be noticed that in some respects the testimony of Christian writers is more valuable than that of either Jews or Gentiles: since none of the writers of that country were brought up as Christians. They were all unbelievers before they were believers; and if such testimony from unbelievers would be valuable, it is still more so from those who showed how thoroughly convinced they were of its truth by becoming believers. Indeed, the best Jewish or Gentile evidence conceivable is that of well-educated men, like St. Paul and St. Luke, who, on the strength of it, became Christians. Lastly, it must be remembered that the argument from silence is proverbially unsound. We have, for instance, over two hundred letters of the younger Pliny, and in only one of these does he mention Christianity. Suppose this one had been lost, what a strong argument could have been formed against the spread of Christianity from the silence of Pliny, yet this one shows its marvellous progress (see Chapter XXII.). This objection, then, is quite insufficient to outweigh the positive testimony in favour of the miracles, to which we have already alluded. (D.) Conclusion. In conclusion we must notice certain rationalistic explanations which have been given of the miracles. It was hardly to be expected that, with such strong evidence in their favour, the modern opponents of Christianity would merely assert that the accounts were pure fiction from beginning to end. Attempts have of course been made to explain the miracles in such a way that, while depriving them of any supernatural character, it may yet be admitted that some such events occurred, which gave rise to the Christian accounts. The miracles of healing are perhaps the easiest to explain in this way, as some wonderful instances of sudden, though natural, cures
have been known. But it is doubtful whether any of Christ's miracles were of such a kind, for St. Paul is careful to distinguish between gifts of healing and working of miracles.[363] Both were evidently known to the early Church, and known to be different. [363] 1 Cor. 12. 9-10, 28. And of course no such explanations will apply to most of the miracles, which have to be got rid of in various other ways. Thus Christ's walking on the sea is explained as His walking on a ridge of sand or rock running out just under the water; the raising of Lazarus as his having had himself buried alive, so that when Christ came, there might be a pretended miracle;[364] and feeding the five thousand as nothing more than the example of Christ and His friends, who so freely shared their small supply with those around them, that others did the same, and thus everyone had a little. It seems scarcely necessary to discuss these theories in detail, as they are all most improbable. [364] This extraordinary theory was maintained by Rénan in the earlier editions of his Life of Jesus, though he afterwards abandoned it. Moreover, their difficulties are all cumulative. The Christian explanation has but one difficulty for all the miracles, which is that they are miracles, and involve the supernatural. Once admit this, and twenty miracles (provided they occur on suitable occasions) are no more difficult to believe than two. But the difficulties of these explanations are all cumulative. If for instance, the raising of Lazarus is explained by his having been buried alive, it does not account for Christ's walking on the sea. If this is explained by the supposed ridge of sand, it does not account for feeding the five thousand, etc. Thus each difficulty has to be added to all the others, so taken together they are quite insuperable. One other point has still to be considered, which is the subject of modern miracles. Why, it is said, are there no miracles now, when they could be properly tested? If they were really employed by God as helps to the spread of His religion, why should they not have
accompanied it at intervals all along, as it is said they did the Jewish religion? They are surely wanted for the support of Christianity at the present day; and if God were, after due warning, to work a public and indisputable miracle every half-century, all the other evidences of Christianity might be dispensed with. The answer to this objection is that the Christian revelation does not claim to be a gradual one, like the Jewish; but a final and complete revelation, made once for all through Christ and His Apostles. Therefore, as there is to be no fresh revelation, there can be no fresh miracles to confirm it. The question of other miracles, such as those which are said to have been worked by Christians at various periods, need not be considered here. If true, they would of course tend to prove the New Testament ones; while, if untrue, they would not disprove them, any more than imitation diamonds would disprove the existence of real diamonds. Of course, it may be replied that God might still work a miracle now by a man, who stated that it was not to confirm anything that he said himself, but merely what the Founder of Christianity had said; and this is no doubt possible. But it would be a different method from that recorded in the Bible, where a messenger from God always brings his own credentials, even though, as in the case of a prophecy, they may not be verified till afterwards. And what reason have we for thinking that God would change His method now? It is also very doubtful whether a public miracle at the present day, would convince everybody. This objection, then, must be put aside, and we therefore conclude, on reviewing the whole subject, that the New Testament miracles are not only credible, but that there is extremely strong evidence in their favour. Indeed their marks of truthfulness, combined with their alleged publicity, form together a very powerful argument. And it is rendered all the stronger by their having been so thoroughly successful. Their object was to establish the truth of Christianity, and this is precisely what they did. The evidence they afforded was so decisive, that a hostile world found it irresistible.
Moreover it is doubtful whether any other religion, except, of course, the Jewish, has ever claimed to have been confirmed by public miracles. Christianity thus rests upon a unique foundation. Unlike other religions, it appealed at first not to abstract reasoning, or moral consciousness, or physical force, but to miraculous events, of the truth or falsehood of which others could judge. They did judge, and they were convinced. We decide, then, that the New Testament miracles are probably true.
CHAPTER XX. THAT THE JEWISH PROPHECIES CONFIRM THE TRUTH OF CHRISTIANITY. (A.) Isaiah's Prophecy of the Lord's Servant. (1.) The historical agreement, very striking. (2.) The doctrinal agreement, equally so. (3.) The modern Jewish interpretation, quite untenable. (B.) The Psalm of the Crucifixion. (1.) Its close agreement, all through. (2.) Two objections, unimportant. (C.) The Divinity of the Messiah. At least three prophecies of this; it is also involved in some hints as to the Doctrine of the Trinity. (D.) Conclusion. Why are not the prophecies plainer? Cumulative nature of the evidence. We propose to consider in this chapter what is called the argument from Prophecy, using the word, as we did in Chapter XI., in the sense of prediction. Now it is a remarkable and undisputed fact that for many centuries before the time of Christ, it was foretold that a member of the Jewish nation—small and insignificant though it was —should be a blessing to all mankind. This promise is recorded as having been made both to Abraham, to Isaac, and to Jacob;[365] and as a matter of fact, Christianity was founded by a Jew, and has
undoubtedly been a blessing to the human race. This is at least a remarkable coincidence. And as we proceed in the Old Testament, the statements about this future Messiah become clearer and fuller, till at last, in the Prophets, we find whole chapters referring to Him, which Christians assert were fulfilled in Christ. [365] Gen. 22. 18; 26. 4; 28.14. This argument is plainly of the utmost importance. Fortunately it is much simplified by the question of dates being altogether excluded. As a rule, the most important point in an alleged prophecy is to show that it was written before its fulfilment. But here this is undisputed, since everyone admits that the whole of the Old Testament, except some of the apocryphal books, was written before the time of Christ. And as the writings have been preserved by the Jews themselves, who are opposed to the claims of Christianity, we may be sure that not a single alteration in its favour has been made anywhere. We will now examine a few of the strongest prophecies, avoiding all those that were only fulfilled in a figurative, or spiritual sense; and selecting whole passages rather than single texts. For though many of these latter are very applicable to Christ, they might also be applicable to someone else. So we will first discuss somewhat fully Isaiah's prophecy of the Lord's Servant, and the Psalm of the Crucifixion; and then examine more briefly a group of prophecies referring to the Divinity of the Messiah. (A.) Isaiah's Prophecy of the Lord's Servant (52. 13-53. 12). It may be pointed out at starting that no one denies the antiquity of the passage, even if it was not written by Isaiah. And it forms a complete whole, closely connected together and not mixed up with any other subject. So in regard to its fulfilment, most of the details mentioned occurred within a few hours. We will consider first the historical, and then the doctrinal agreement. (1.) The Historical Agreement.
With regard to this, the following is the translation from the Revised Version, together with the corresponding events. It will be observed that the sufferings of the Servant are usually expressed in the past tense, and his triumph in the future, the prophet placing himself, as it were, between the two. But the Hebrew tenses are rather uncertain, and what is translated as past in the Revised Version is translated as future in the Authorised (e.g., 53. 2). 52. 13. 'Behold, my servant shall deal wisely, he shall be exalted and lifted up, and shall be very high. The excellence of Christ's teaching and conduct is now generally admitted; while as to His exalted position, He is worshipped by millions of men. 14. 'Like as many were astonied at thee (his visage was so marred more than any man, and his form more than the sons of men) so shall he sprinkle many nations; Yet at the time of His death, which was public so that many saw Him, the cruel treatment He had received must have terribly disfigured His face and body. 15. 'Kings shall shut their mouths at him: for that which had not been told them shall they see; and that which they had not heard shall they understand. But now even Kings are silent with reverence,[366] when contemplating such a wonderful life. 53. 1. 'Who hath believed our report? Indeed what the prophet is about to declare, is so marvellous that it can scarcely be believed. 'and to whom hath the arm of the Lord been revealed? The Arm of the Lord evidently means some instrument, or Person, which God uses for His work, as a man might use his arm.[367] And here it must be a Person, from the following words, 'For he grew up,' etc. It is thus a most suitable term for the Messiah, who was to be recognised by hardly anyone. 2. 'For he grew up before him as a tender plant, and as a root out of a dry ground: This was because He lived at a place (Nazareth) which was always regarded as dry ground so far as anything good was concerned.[368] he hath no form nor comeliness; and when we see him, there is no beauty that we should desire him. Moreover, His appearance was humble, and when at His trial, Pilate presented Him to the people, they did not desire Him. 3. 'He was despised, and rejected of men; a man of sorrows, and acquainted with grief: and as one from whom men hide But they at once rejected Him as they had done often before.
their face he was despised, and we esteemed him not. 4. 'Surely he hath borne our griefs, and carried our sorrows: yet we did esteem him stricken, smitten of God, and afflicted. While His life was not only one of grief and sorrow, but such a death seemed to show that He was accursed of God, for the Jews so regarded anyone who was crucified.[369] 5. 'But he was wounded for our transgressions, he was bruised for our iniquities: the chastisement of our peace was upon him; and with his stripes we are healed. The scourging and other ill-treatment is here referred to; including probably the nails, and spear, for the word translated wounded is literally pierced. 6. 'All we like sheep have gone astray; we have turned every one to his own way; and the Lord hath laid on him the iniquity of us all. 7. 'He was oppressed, yet he humbled himself and opened not his mouth; as a lamb that is led to the slaughter, and as a sheep that before her shearers is dumb; yea, he opened not his mouth. Christ, who is sometimes called the Lamb of God, not only bore His ill-treatment patiently, but refused to plead at either of His trials (the verse repeats twice He opened not His mouth) to the utter astonishment of His judges.[370] 8. 'By oppression and judgment he was taken away; and as for his generation, who among them considered that he was cut off out of the land of the living? for the transgression of my people was he stricken. He was not killed accidentally, or by the mob, but had a judicial trial; and was most unjustly condemned. While few, if any, of His contemporaries understood the real meaning of His death. 9. 'And they made his grave with the wicked, and with the rich in his death (i.e., when he was dead. Comp. Ps. 6. 8); He was appointed to die between two robbers, and would doubtless have been buried with them, had not Joseph of Arimathea intervened; when, in strange contrast with His ignominious death, He was honourably buried, with costly spices, and in a rich man's tomb. although he had done no violence, neither was any deceit in his mouth. Although His judge repeatedly declared that He was innocent. 10. 'Yet it pleased the Lord to bruise him; he hath put him to grief: when thou shalt make his soul an offering for sin, he shall see his seed, he shall prolong his days, and the pleasure of the Lord shall prosper in his hand. Yet after His death He was to see His seed, and prolong His days, i.e., rise again from the dead. The word seed cannot mean here, actual children,[371] since He was to obtain them by His death. But it may well refer to the disciples, whom Christ saw after His Resurrection, and called His children.[372]
11. 'He shall see of the travail of his soul, and shall be satisfied: by his knowledge shall my righteous servant justify many: and he shall bear their iniquities. And this is confirmed by their being spoken of as the travail of His soul, not body. While the latter expression also implies that He had had some intense mental struggle comparable to the bodily pains of childbirth; which is very suitable to His mental agony in the Garden and on the Cross. 12. 'Therefore will I divide him a portion with the great, and he shall divide the spoil with the strong; His subsequent triumph in the Christian Church is here alluded to. because he poured out his soul unto death, This implies that His sufferings were of some duration; and is thus very appropriate to a lingering death like crucifixion. and was numbered with the transgressors: yet he bare the sin of many, and made intercession for the transgressors.' While the closing words exactly agree with His dying a shameful death between two robbers; yet praying for His murderers, 'Father, forgive them.' [366] Comp. Job 29. 9. [367] Comp. Isa. 40. 10; 51. 9. [368] John 1. 46. [369] Deut. 21. 23; Gal. 3. 13. [370] Matt. 26. 62; 27. 14. [371] Comp. Isa. 1. 4. [372] Mark 10. 24; John 21. 5. It seems hardly necessary to insist on the agreement shown above; it is indisputable. The sufferings and the triumph of the Lord's Servant are foretold with equal confidence and with equal clearness, though they might well have seemed incompatible. (2.) The Doctrinal Agreement. But the significance of the passage does not depend on these prophecies alone, though they are sufficiently remarkable, but on the meaning which the writer assigns to the great tragedy. It is the Christian doctrine concerning Christ's death, and not merely the events attending it, which is here insisted on. This will be best
shown by adopting the previous method of parallel columns, showing in the first the six chief points in the Christian doctrine, and in the other the prophet's words corresponding to them. All mankind are sinners. 'All we like sheep have gone astray.' Christ alone was sinless. 'My righteous servant.' 'He had done no violence, neither was any deceit in his mouth.' He suffered not for His own sins, but for those of others. Nor was this the mere accidental suffering of an innocent man for a guilty one; it was a great work of atonement, an offering for sin. This is the central feature of the Christian doctrine, and it is asserted over and over again in the prophecy, which is above all that of a Saviour. 'Surely he hath borne our griefs, and carried our sorrows.' 'He was wounded for our transgressions, he was bruised for our iniquities; the chastisement of (i.e., which procured) our peace was upon him; and with his stripes we are healed.' 'The Lord hath laid on him the iniquity of us all.' 'For the transgression of my people was he stricken.' 'Thou shalt make his soul an offering for sin.' 'He shall bear their iniquities.' 'He bare the sin of many.' And this Atonement was the fulfilment of the old Jewish sacrifices; especially that of the Paschal Lamb; so there was a special fitness in Christ's being put to death at the time of the Passover. This is shown by the language employed, the offering for sin being the same word as that used for the old guilt-offering.[373] And the curious expression So shall he sprinkle many nations evidently refers to the sprinkling of the blood in the Jewish sacrifices, as the same word is used, and means cleansing them from sin.[374] Yet it availed not only for the Jews, but for all mankind. The many nations must include Gentiles as well as Jews. Lastly, Christ's sacrifice was voluntary; He freely laid down His life, no one took it from Him (John 10. 18). 'He poured out his soul unto death,' implies that the act was voluntary, and this is rendered still clearer from the context; for it was because He did this that He was to divide the spoil, etc. And the words He humbled Himself, also imply that the humiliation was voluntary. [373] E.g., Lev. 7. 1. [374] E.g., Lev. 16. 19. All this, it is plain, exactly suits the Christ in whom Christians believe; and it does not and cannot suit anyone else, since several of the Christian doctrines are quite unique, and do not occur in the Jewish
or any other religion. This is indeed so striking, that if anyone acquainted with Christianity, but unacquainted with Isaiah, came across the passage for the first time, he would probably refer it to one of St. Paul's Epistles. And every word of it might be found there with perfect fitness. (3.) The modern Jewish interpretation. Now, what can be said on the other side? Many of the ancient Jews interpreted the passage as referring to their future Messiah;[375] but the modern Jews (and most critics who disbelieve in prophecy) refer it to the Jewish nation, or to the religious part of it, which they say is here personified as a single man, the Servant of the Lord. And it must of course be admitted that Isaiah does frequently speak of the Jews as God's servant (e.g., 'But thou Israel, my servant, and Jacob whom I have chosen,')[376] though he nowhere else uses the term 'my righteous servant,' which he does here, and which would have been inapplicable to the nation. [375] References are given in Edersheim's 'Life and Times of Jesus the Messiah,' 1901, vol. ii., p. 727. [376] Isa. 41. 8. But it is important to remember that this prophecy does not stand alone, and a little before, we read in a similar passage, 'It is too light a thing that thou shouldest be my servant to raise up the tribes of Jacob, and to restore the preserved of Israel: I will also give thee for a light to the Gentiles, that thou mayest be my salvation unto the end of the earth. Thus saith the Lord, the Redeemer of Israel, and his Holy One, to him whom man despiseth, to him whom the nation abhorreth, to a servant of rulers: Kings shall see and arise; princes, and they shall worship.'[377] [377] Isa. 49. 6-7; comp. 42. 1-6. Here it will be noticed the Lord's servant is clearly distinguished from both Jacob and Israel, and evidently means the Messiah. While His bringing salvation to the Gentiles, as well as to the Jews; His
humiliation in being despised by men and hated by the Jewish nation; and His subsequent triumph, even Kings submitting themselves to Him; are all alluded to, much as they are in the present passage. No doubt there is a difficulty in the prophet thus passing from one meaning of the word servant to another (especially, in a closely connected passage),[378] and various attempts have been made to explain it; but it does not alter the fact that he does so. Perhaps the best explanation is that Israel was intended to be God's Servant, but owing to their sins became unfitted; when God promised in the future to raise up a righteous servant, who should do all His pleasure and atone for Israel's failure. And, it may be added, the term Servant is applied to the Messiah both by Ezekiel and Zechariah, as well as in the New Testament.[379] [378] Isa. 49. 3, 5. [379] Ezek. 34. 23; Zech. 3. 8; Acts 3. 13 (R.V.). Moreover, the Jewish interpretation not only leaves all the details of the prophecy unexplained and inexplicable, but ignores its very essence, which, as before said, is the atoning character of the sufferings. No one can say that the sufferings of the Jews were voluntary, or that they were not for their own sins, but for those of other people, which were in consequence atoned for. Or, to put the argument in other words, if the He refers to the Jewish nation, to whom does the our refer in such sentences as He was wounded for our transgressions? While v. 8 expressly says that the Jews (God's people) were not the sufferers, but those for whom He suffered. (For the transgression of my people was he stricken.) This interpretation then is hopelessly untenable, and the passage either means what Christians assert, or it means nothing. In conclusion, it must be again pointed out that all these minute historical details attending Christ's death, and all these remarkable Christian doctrines concerning it, are all found within fifteen verses of a writing many centuries older than the time of Christ. It would be
hard to over-estimate the great improbability of all this being due to chance; indeed, such a conclusion seems incredible. (B.) The Psalm of the Crucifixion (Ps. 22).[380] [380] This is discussed more fully in an article in the Churchman, April, 1912, by the present writer. We pass on now to another most remarkable prophecy; for this well- known Psalm describes what can only be regarded as a crucifixion. The decisive verse is of course, They pierced my hands and my feet; but even apart from this, the various sufferings described cannot all be endured in any other form of death, such as stoning or beheading. And the Psalm agrees with the Death of Christ, both in its numerous details, and in its whole scope and meaning. We will therefore consider this close agreement first, and then some of the objections. (1.) Its close agreement. We need not quote the Psalm, as it is so well known; but will point out the agreement verse by verse. Ver. 1. His feeling forsaken by God, and using these actual words: 'My God, my God, why hast thou forsaken me?' 2. as well as praying for deliverance during the previous night; 3. though in spite of His sufferings, He casts no reproach upon God. 4. His belonging to God's chosen people, the Jews, so that He could speak of our fathers; 5. who had so often been helped by God before. 6. His pitiable condition in being exposed to the scorn and reproach of men, and despised by
the people. 7. His being lifted up to die in public, so that those who passed by could see Him; and the way in which they mocked Him, shaking their heads, etc. 8. The exact words they used: He trusted on the Lord that He would deliver him, let Him deliver him seeing He delighteth in him (margin). These words show that the speakers themselves were Jews, and that He was thus put to death among His own nation. And the last clause can only be meant ironically in the sense that the Sufferer claimed that God delighted in him, claimed, that is, in some special sense to be beloved by God. 9. And, as a matter of fact, God had always watched over Him, and had saved Him in His infancy from being slain by Herod. 10. And in return His whole life had been dedicated to God; so that He could say that God had been His God, even from His birth. 11. His being abandoned by His disciples, and left without a helper; 12. though surrounded by His enemies, described as bulls of Bashan. This curious term is used elsewhere for the unjust rulers of the people, [381] and was therefore very applicable to the chief priests and rulers, who had so unjustly condemned Him, and now stood round the Cross reviling Him.
[381] Amos. 4. 1. 13. And they continually insulted Him, gaping with the mouth being a common expression of contempt;[382] ravening appropriate to the way in which they had thirsted for His blood before Pilate; and roaring to the great noise and tumult made at the time. [382] E.g., Job 16. 10. 14. His side being pierced, so that there poured out a quantity of watery fluid (mixed with clots of blood), the probable cause of this— the rupture of the heart[383] —being also hinted at; while His bones were nearly out of joint, through the weight of the suspended Body. [383] See 'The Physical Cause of the Death of Christ,' by Dr. Symes Thompson, 1904. 15. His suffering extreme weakness, and extreme thirst, immediately before His death.[384] [384] Lam. 4. 4; John 19. 28-30. 16. His being crucified (i.e., His hands and feet being pierced), the men who did this being here called dogs. They seem to have been a special set of men, different from the Jews who had before been mocking Him. And as this was the very term used by Christ Himself for the Gentiles, in distinction to the Jews,[385] it was peculiarly appropriate to the Gentile (Roman) soldiers who crucified Him. [385] Matt. 15. 26.
17. And they also exposed and stretched out His Body, so that the bones stood out in relief. And they then stood watching Him; 18. and divided His garments among them, casting lots for one of them. 19. Then follows a short prayer. 20. The term sword, like the dog, the lion's mouth, and the wild oxen, need not be pressed literally; but may be used here (as in other places)[386] for any violent death. And in the New Testament it seems employed for all punishments, including probably a death by crucifixion (St. Peter's).[387] [386] Comp. 2 Sam. 11. 24; 12. 9. [387] Rom. 13. 4; Matt. 26. 52. 21. Yet in spite of His troubles, and even death, He feels sure of deliverance. 22. And now the strain suddenly changes, the Sufferer is restored to life and freedom and at once declares God's name unto His brethren. And this exactly agrees with Christ's now declaring for the first time God's complete Name of, Father, Son, and Holy Ghost, unto His brethren, as He calls them, the Apostles. [388] While if we identify this appearance with that to the five hundred, it was literally in the midst of the congregation—in the presence, that is, of the first large Christian assembly. [388] Matt. 28. 10, 19.
23. Moreover, His deliverance is of world-wide significance, and great blessings are to follow from it. These commence with the Jews, who were to praise and glorify God; though with a strange feeling of awe and fear; all of which was exactly fulfilled.[389] [389] Acts 2. 43-47. 24. And the blessings are somehow connected with God's not having despised, but having accepted, His sufferings. 25. And they include a reference to some vows (meaning uncertain); 26. and to a wonderful feast generally thought to refer to the Holy Communion. 27. And the blessings then extend to the Gentile nations also, even to the most distant parts of the world, who are now to become worshippers of the true God, Jehovah. And, as a matter of fact, Christians exist in all known countries, and wherever there are Christians, Jehovah is worshipped. 28. To Whom the whole earth, both the Jewish kingdom and the Gentile nations, really belongs. 29. And to Whom everyone will eventually bow down. 30. After this we read of a seed serving Him, probably used here, as in Isaiah, for disciples, each generation of whom is to tell of this wonderful deliverance to the next. And this they have been doing for eighteen centuries.
31. And so they will continue doing to generations that are yet unborn. While the closing words, He hath done it (R.V.) are often taken as referring to the whole Psalm, meaning that the work of suffering and atonement was now complete, It is done;[390] and they would thus correspond to Christ's closing words on the Cross, It it finished. [390] Hengstenberg, Commentary on Psalms, 1867, vol. i., 396. Everyone must admit that the agreement all through is very remarkable; though there are two slight objections. (2.) Two objections. The first is that there is nothing to show that the writer meant the Psalm to refer to the Messiah at all, though, strange to say, some of the Jews so interpreted it;[391] therefore if there is an agreement, it is at most only a chance coincidence. But the idea of all these coincidences being due to chance is most improbable. And there certainly is some indication that it refers to the Messiah, since, as we have seen, it leads up to the conversion of the Gentiles, which the other Jewish prophets always associate with the times of the Messiah. [391] Edersheim, 1901, vol. ii., 713. Moreover, if the Psalm does not refer to Christ, it is difficult to see to whom it does refer, since it is quite inapplicable to David, or Hezekiah, or anyone else at that time; as crucifixion was not a Jewish punishment, though dead bodies were sometimes hung on trees. Yet, as just said, verses 7-8 show that the Sufferer was put to death among his own nation. This strange anomaly of a Jew being put to death among Jews, though not in the Jewish manner by stoning, but by crucifixion, exactly suits the time of Christ, when Judæa was a Roman province, and crucifixion a Roman punishment.
Many of the details also are quite inapplicable. David, for instance, never had his garments divided among his enemies; yet (even apart from our Gospels) there can be little doubt that the garments of Christ were so divided, as the clothes of a prisoner were usually taken by the guard who executed him. And any such reference (to David, etc.) is rendered still more improbable, because the sufferer appears to have no sense of sin, and never laments his own wickedness, as the writers so frequently do when speaking about themselves. And here also the Psalm is entirely applicable to Christ, since (as we shall see in the next chapter) His sinlessness was a striking feature in His character. Nor again did the deliverance of David in any way lead to the conversion of the Gentiles, which, as just said, is the grand climax of the Psalm, and excludes all other interpretations. But in any case this objection (which is also made to other Old Testament prophecies) cannot be maintained; for who, we must ask, was their real author? Was it the human prophet, or was it God Who inspired the prophet to write as he did? And the prophets themselves emphatically declared that it was the latter. The word of the Lord came unto them, or a vision was granted unto them, and they had to proclaim it, whether they liked it or not. In fact, as St. Matthew says, it was not really the prophet who spoke, but God, who spoke through the prophet.[392] There is thus no reason for thinking that they either knew, or thought they knew, the whole meaning of their prophecies; and the objection may be dismissed at once. [392] E.g., Matt. 1. 22. The second objection is, that some of the events fulfilling this, and other Old Testament prophecies, never occurred, but were purposely invented. This, however, destroys altogether the moral character of the Evangelists, who are supposed to tell deliberate falsehoods, in order to get a pretended fulfilment of an old prophecy. And the difficulty of admitting this is very great. Moreover, such explanations
can only apply to a very few cases; since, as a rule, the events occurred in public, and must therefore have been well known at the time. And even in those cases where the event was so trivial, that it might possibly have been invented, such an explanation is often untenable. Take, for example, the manner in which Christ on the cross was mocked by His enemies, who said, 'He trusted in God, let him deliver him now if he desireth him.'[393] A more probable incident under the circumstances can scarcely be imagined, the chief priests quoting the familiar language (just as men sometimes quote the Bible now) without thinking of its real significance. But, supposing the words were never uttered, is it conceivable that the Evangelist (or anyone else) would have invented them in order to get a pretended fulfilment of this Psalm, where the Crucified One is mocked with almost identical words; yet have never pointed out the fulfilment himself, but have trusted to the chance of his readers discovering it? [393] Matt. 27. 43. Neither of these objections, then, is of much importance; while the agreement of the Psalm with the events attending the death and Resurrection of Christ, seems, as in the previous case, to be far too exact to be accidental. (C.) The Divinity of the Messiah. Our last example shall be of a different kind from the others. It is that the Old Testament contains several passages which show that the future Messiah was to be not only Superhuman, but Divine. And considering the strong Monotheism of the Jews this is very remarkable. The following are three of the most important:— 'For unto us a child is born, unto us a son is given; and the government shall be upon his shoulder: and his name shall be called Wonderful, Counsellor, Mighty God, Everlasting Father, Prince of Peace.'[394] Here we have a plain statement of the Divinity of One Who should be born a child. The two words translated Mighty God
are incapable of any other translation, and no other is suggested for them in the margin of either the Authorised or Revised Version; while the same two words occur in the next chapter, where they plainly mean Mighty God and nothing else. Moreover, the term Everlasting Father is literally Father of Eternity (see margin) and means the Eternal One. This is another divine title, and does not conflict with the Christian doctrine that it was the Son, and not the Father, Who became Incarnate. While the following words, that of the increase of His government there shall be no end, and that it should be established for ever, also point to a Divine Ruler, in spite of the reference to David's throne. And it is significant that a few verses before it is implied that the Ministry of this future Messiah should commence in the land of Zebulon, and Naphtali, by the Sea of Galilee; where, as a matter of fact, Christ's Ministry did commence. [394] Isa. 9. 6; 10. 21; 9. 1-2. 'But thou, Bethlehem Ephrathah, which art little to be among the thousands of Judah, out of thee shall one come forth unto me that is to be ruler in Israel; whose goings forth are from of old, from everlasting.'[395] Here we have a prophecy of the birth of One who had existed from everlasting; thus showing the Pre-existence and apparent Divinity of the Messiah, who was to be born at Bethlehem, where, again, as a matter of fact, Christ actually was born. [395] Mic. 5. 2. 'Awake, O sword, against my shepherd, and against the man that is my fellow, saith the Lord of hosts.'[396] The word translated fellow is only found elsewhere in Leviticus, where it is usually translated neighbour, and always implies an equality between the two persons. [397] Thus God speaks of the Shepherd who was to be slain with the sword (a term, as before said, used for any violent death), as equal with Himself, and yet at the same time Man; so no one but a Messiah who is both God and Man—Fellow-God as well as fellow- man—can satisfy the language.
[396] Zech. 13. 7. [397] Lev. 6. 2; 18. 20; 19. 11, 15, 17; 24. 19; 25. 14, 15, 17. And here again the reference to Christ is confirmed by the fact that several incidents in His Passion are alluded to, in some of which His Divinity is likewise asserted. The most important are the way in which He (the Just Saviour) rode into Jerusalem on an ass; and the rejoicing with which He was received, when the people welcomed Him as their King. And the fact that He (the Lord Jehovah) should be sold for thirty pieces of silver, the money being cast down in the House of the Lord, and afterwards given to the potter; and also that He (again the Lord Jehovah) should be pierced.[398] These are, it is true, expressed in figurative language, and often mixed up with other subjects; so no instance by itself, affords a strong argument. But still their all occurring so close together, and all leading up to the violent death of a man, who was yet the fellow, or equal, with God, can scarcely be accidental. While the prophecy, like so many others, ends with the conversion of the Gentiles, the Lord Jehovah being recognised as King over all the earth; which seems to place the Messianic character beyond dispute. [398] Zech. 9. 9; 11. 12-13; 12. 10; 14. 9; Luke 19. 37-38. The Divinity of the Messiah is also involved in some hints which occur in the Old Testament as to the doctrine of the Trinity. For instance, the Hebrew word for God, Elohim, is a plural word, though, strange to say, it generally takes a singular adjective, and verb. Thus if we tried to represent it in English, the first verse of the Bible would read, 'In the beginning the Gods, He created the heaven and the earth.' Attempts have of course been made to reduce the significance of this by pointing out that a few other Hebrew words, such as lord and master, sometimes do the same; or by regarding it as a survival from some previous polytheistic religion; or else as being what is called the plural of Majesty, a sort of royal We. This, however, does not seem to have been in use in early times, and never occurs in the Bible, where kings always speak of themselves in the singular.[399] Anyhow it is very remarkable that the Jews should
Welcome to our website – the perfect destination for book lovers and knowledge seekers. We believe that every book holds a new world, offering opportunities for learning, discovery, and personal growth. That’s why we are dedicated to bringing you a diverse collection of books, ranging from classic literature and specialized publications to self-development guides and children's books. More than just a book-buying platform, we strive to be a bridge connecting you with timeless cultural and intellectual values. With an elegant, user-friendly interface and a smart search system, you can quickly find the books that best suit your interests. Additionally, our special promotions and home delivery services help you save time and fully enjoy the joy of reading. Join us on a journey of knowledge exploration, passion nurturing, and personal growth every day! ebookbell.com

Getting Started With Spring Framework J Sharma Ashish Sarin

  • 1.
    Getting Started WithSpring Framework J Sharma Ashish Sarin download https://ebookbell.com/product/getting-started-with-spring- framework-j-sharma-ashish-sarin-42536226 Explore and download more ebooks at ebookbell.com
  • 2.
    Here are somerecommended products that we believe you will be interested in. You can click the link to download. Getting Started With Roo Rapid Application Developent For Java And Spring 1st Edition Josh Long https://ebookbell.com/product/getting-started-with-roo-rapid- application-developent-for-java-and-spring-1st-edition-josh- long-23135206 Getting Started With Natural Language Processing Final Release 1st Edition Ekaterina Kochmar https://ebookbell.com/product/getting-started-with-natural-language- processing-final-release-1st-edition-ekaterina-kochmar-46078164 Getting Started With Uno Platform And Winui 3 Handson Building Of Crossplatform Desktop Mobile And Web Applications That Can Run Anywhere 1st Edition Andrew Hoefling https://ebookbell.com/product/getting-started-with-uno-platform-and- winui-3-handson-building-of-crossplatform-desktop-mobile-and-web- applications-that-can-run-anywhere-1st-edition-andrew- hoefling-46364362 Getting Started With Secure Embedded Systems Alexandru Radovici https://ebookbell.com/product/getting-started-with-secure-embedded- systems-alexandru-radovici-47255148
  • 3.
    Getting Started WithVisual Studio 2022 Learning And Implementing New Features 2nd Dirk Strauss https://ebookbell.com/product/getting-started-with-visual- studio-2022-learning-and-implementing-new-features-2nd-dirk- strauss-47378260 Getting Started With Microsoft Viva An End User Guide To Business Transformation 1st Edition Darce Hess https://ebookbell.com/product/getting-started-with-microsoft-viva-an- end-user-guide-to-business-transformation-1st-edition-darce- hess-47554262 Getting Started With Forex Trading Using Python Beginners Guide To The Currency Market And Development Of Trading Algorithms 1st Edition Alex Krishtop https://ebookbell.com/product/getting-started-with-forex-trading- using-python-beginners-guide-to-the-currency-market-and-development- of-trading-algorithms-1st-edition-alex-krishtop-48054962 Getting Started With Angular Create And Deploy Angular Applications 1st Edition Victorhugogarcia https://ebookbell.com/product/getting-started-with-angular-create-and- deploy-angular-applications-1st-edition-victorhugogarcia-48081270 Getting Started With Python Data Analysis Phuong Voth Martin Czygan https://ebookbell.com/product/getting-started-with-python-data- analysis-phuong-voth-martin-czygan-49052760
  • 6.
    Getting started withSpring Framework Second Edition Ashish Sarin, J Sharma
  • 7.
    Table of contents Preface Howto use this book Conventions used in this book Feedback and questions About the authors Chapter 1 – Introduction to Spring Framework 1-1 Introduction 1-2 Spring Framework modules 1-3 Spring IoC container 1-4 Benefits of using Spring Framework Consistent approach to managing local and global transactions Declarative transaction management Security JMX (Java Management Extensions) JMS (Java Message Service) Caching 1-5 A simple Spring application Identifying application objects and their dependencies Creating POJO classes corresponding to identified application objects Creating the configuration metadata Creating an instance of Spring container Access beans from the Spring container 1-6 Frameworks built on top of Spring 1-7 Summary
  • 8.
    Chapter 2 –Spring Framework basics 2-1 Introduction 2-2 Programming to interfaces design principle Scenario: Dependent class contains reference to the concrete class of dependency Scenario: Dependent class contains reference to the interface implemented by the dependency Spring’s support for ‘programming to interfaces’ design approach 2-3 Different approaches to instantiating Spring beans Instantiating beans via static factory methods Instantiating beans via instance factory methods 2-4 Dependency injection techniques Setter-based DI Constructor-based DI 2-5 Bean scopes Singleton Prototype Choosing the right scope for your beans 2-6 Summary Chapter 3 - Configuring beans 3-1 Introduction 3-2 Bean definition inheritance MyBank – Bean definition inheritance example What gets inherited ? 3-3 Constructor argument matching Passing simple values and bean references using <constructor-arg> element Constructor argument matching based on type Constructor argument matching based on name
  • 9.
    3-4 Configuring differenttypes of bean properties and constructor arguments Built-in property editors in Spring Specifying values for different collection types Specifying values for arrays Default collection implementation for <list>, <set> and <map> elements 3-5 Built-in property editors CustomCollectionEditor CustomMapEditor CustomDateEditor 3-6 Registering property editors with the Spring container Creating a PropertyEditorRegistrar implementation Configuring the CustomEditorConfigurer class 3-7 Concise bean definitions with p and c namespaces p-namespace c-namespace 3-8 Spring’s util schema <list> <map> <set> <properties> <constant> <property-path> 3-9 FactoryBean interface MyBank application – Storing events in the database MyBank – FactoryBean example Accessing the FactoryBean instance 3-10 Summary Chapter 4 - Dependency injection
  • 10.
    4-1 Introduction 4-2 Innerbeans 4-3 Explicitly controlling the bean initialization order with depends- on attribute MyBank – implied dependencies between beans Implicit dependency problem 4-4 Singleton- and prototype-scoped bean’s dependencies Singleton-scoped bean’s dependencies Prototype-scoped bean’s dependencies 4-5 Obtaining new instances of prototype beans inside singleton beans ApplicationContextAware interface <lookup-method> element <replaced-method> element 4-6 Autowiring dependencies byType constructor byName default / no Making beans unavailable for autowiring Autowiring limitations 4-7 Summary Chapter 5 - Customizing beans and bean definitions 5-1 Introduction 5-2 Customizing bean’s initialization and destruction logic Making Spring invoke cleanup method specified by the destory- method attribute Cleanup methods and prototype-scoped beans Specifying default bean initialization and destruction methods for all beans
  • 11.
    InitializingBean and DisposableBeanlifecycle interfaces JSR 250’s @PostConstruct and @PreDestroy annotations 5-3 Interacting with newly created bean instances using BeanPostProcessor BeanPostProcessor example – Validating bean instances BeanPostProcessor example – Resolving bean dependencies BeanPostProcessor behavior for FactoryBeans RequiredAnnotationBeanPostProcessor DestructionAwareBeanPostProcessor 5-4 Modifying bean definitions using BeanFactoryPostProcessor BeanFactoryPostProcessor example PropertySourcesPlaceholderConfigurer PropertyOverrideConfigurer 5-5 Summary Chapter 6- Annotation-driven development with Spring 6-1 Introduction 6-2 Identifying Spring components with @Component 6-3 @Autowired - autowiring dependencies by type 6-4 @Qualifier – autowiring dependencies by name 6-5 JSR 330’s @Inject and @Named annotations 6-6 JSR 250’s @Resource annotation 6-7 @Scope, @Lazy, @DependsOn and @Primary annotations 6-8 Simplifying component configuration using @Value annotation 6-9 Validating objects using Spring’s Validator interface 6-10 Specifying constraints using JSR 303 annotations JSR 303 support in Spring 6-11 Programmatically configuring Spring beans using @Configuration and @Bean annotations
  • 12.
    6-12 Summary Chapter 7- Database interaction using Spring 7-1 Introduction 7-2 MyBank application’s requirements 7-3 Developing the MyBank application using Spring’s JDBC module Configuring a data source Creating DAOs that use Spring’s JDBC module classes 7-4 Developing the MyBank application using Hibernate Configuring SessionFactory instance Creating DAOs that use Hibernate API for database interaction 7-5 Transaction management using Spring MyBank’s transaction management requirements Programmatic transaction management Declarative transaction management Spring’s support for JTA 7-6 Summary Chapter 8 - Messaging, emailing, asynchronous method execution, and caching using Spring 8-1 Introduction 8-2 MyBank application’s requirements 8-3 Sending JMS messages Configuring ActiveMQ broker to run in embedded mode Configuring a JMS ConnectionFactory Sending JMS messages using JmsTemplate Sending JMS messages within a transaction Dynamic JMS destinations and JmsTemplate configuration JmsTemplate and message conversion 8-4 Receiving JMS messages
  • 13.
    Synchronously receiving JMSmessages using JmsTemplate Asynchronously receiving JMS messages using message listener containers 8-5 Sending emails 8-6 Task scheduling and asynchronous execution TaskExecutor interface TaskScheduler interface @Async and @Scheduled annotations 8-7 Caching Configuring a CacheManager Caching annotations - @Cacheable, @CacheEvict and @CachePut 8-8 Running the MyBank application 8-9 Summary Chapter 9 - Aspect-oriented programming 9-1 Introduction 9-2 A simple AOP example 9-3 Spring AOP framework Proxy creation expose-proxy attribute 9-4 Pointcut expressions @Pointcut annotation execution and args pointcut designators bean pointcut designator Annotations-based pointcut designators 9-5 Advice types Before advice After returning advice After throwing advice After advice
  • 14.
    Around advice 9-6 SpringAOP - XML schema-style Configuring an AOP aspect Configuring an advice Associating a pointcut expression with an advice 9-7 Summary Chapter 10 – Spring Web MVC basics 10-1 Introduction 10-2 Directory structure of sample web projects 10-3 Understanding the ‘Hello World’ web application HelloWorldController.java – Hello World web application’s controller class helloworld.jsp – JSP page that shows the ‘Hello World !!’ message myapp-config.xml – Web application context XML file web.xml – Web application deployment descriptor 10-4 DispatcherServlet – the front controller Accessing ServletContext and ServletConfig objects 10-5 Developing controllers using @Controller and @RequestMapping annotations Developing a ‘Hello World’ web application using an annotated controller 10-6 MyBank web application’s requirements 10-7 Spring Web MVC annotations - @RequestMapping and @RequestParam Mapping requests to controllers or controller methods using @RequestMapping @RequestMapping annotated methods arguments @RequestMapping annotated methods return types Passing request parameters to controller methods using @RequestParam
  • 15.
    10-8 Validation 10-9 Handlingexceptions using @ExceptionHandler annotation 10-11 Loading root web application context XML file(s) 10-12 Summary Chapter 11 – Validation and data binding in Spring Web MVC 11-1 Introduction 11-2 Adding and retrieving model attributes using @ModelAttribute annotation Adding model attributes using method-level @ModelAttribute annotation Retrieving model attributes using @ModelAttribute annotation Request processing and @ModelAttribute annotated methods Behavior of @ModelAttribute annotated method arguments RequestToViewNameTranslator 11-3 Caching model attributes using @SessionAttributes annotation 11-4 Data binding support in Spring WebDataBinder – data binder for web request parameters Configuring a WebDataBinder instance Allowing or disallowing fields from data binding process Inspecting data binding and validation errors using BindingResult object 11-5 Validation support in Spring Validating model attributes using Spring’s Validator interface Specifying constraints using JSR 303 annotations Validating objects that use JSR 303 annotations 11-6 Spring’s form tag library HTML5 support in Spring’s form tag library 11-7 Summary Chapter 12 –Developing RESTful web services using Spring Web
  • 16.
    MVC 12-1 Introduction 12-2 Fixeddeposit web service 12-3 Implementing a RESTful web service using Spring Web MVC JSON (JavaScript Object Notation) FixedDepositWS web service implementation 12-4 Accessing RESTful web services using RestTemplate 12-5 Converting Java objects to HTTP requests and responses and vice versa using HttpMessageConverter 12-6 @PathVariable and @MatrixVariable annotations 12-7 Summary Chapter 13 – More Spring Web MVC – internationalization, file upload and asynchronous request processing 13-1 Introduction 13-2 Pre- and post-processing requests using handler interceptors Implementing and configuring a handler interceptor 13-3 Internationalizing using resource bundles MyBank web application’s requirements Internationalizing and localizing MyBank web application 13-4 Asynchronously processing requests Asynchronous request processing configuration Returning Callable from @RequestMapping methods Returning DeferredResult from @RequestMapping methods Setting default timeout value Intercepting asynchronous requests 13-5 Type conversion and formatting support in Spring Creating a custom Converter Configuring and using a custom Converter Creating a custom Formatter
  • 17.
    Configuring a customFormatter Creating AnnotationFormatterFactory to format only @AmountFormat annotated fields Configuring AnnotationFormatterFactory implementation 13-6 File upload support in Spring Web MVC Uploading files using CommonsMultipartResolver Uploading files using StandardServletMultipartResolver 13-7 Summary Chapter 14 – Securing applications using Spring Security 14-1 Introduction 14-2 Security requirements of the MyBank web application 14-3 Securing MyBank web application using Spring Security Web request security configuration Authentication configuration Securing JSP content using Spring Security’s JSP tab library Securing methods 14-4 MyBank web application - securing FixedDepositDetails instances using Spring Security’s ACL module Deploying and using ch14-bankapp-db-security project Database tables to store ACL and user information User authentication Web request security JdbcMutableAclService configuration Method-level security configuration Domain object instance security Managing ACL entries programmatically MutableAcl and security 14-5 Summary Appendix A – Importing and deploying sample projects in Eclipse IDE (or IntelliJ IDEA)
  • 18.
    A-1 Setting upthe development environment A-2 Importing a sample project into Eclipse IDE (or IntelliJ IDEA) Importing a sample project Configuring the M2_REPO classpath variable in the Eclipse IDE A-3 Configuring Eclipse IDE with Tomcat 7 server A-4 Deploying a web project on Tomcat 7 server Running the Tomcat 7 server in embedded mode
  • 19.
    Preface How to usethis book Download sample projects This book comes with many sample projects that you can download from the following Google Code project: http://code.google.com/p/getting-started-with- spring-framework-2edition/. You can download the sample projects as a single ZIP file or you can checkout the sample projects using SVN. For more details, refer to the above URL. Import sample projects into your Eclipse or IntelliJ IDEA IDE If you see IMPORT chapter<chapter-number>/<project name> at any point while reading the book, you should import the specified project into your Eclipse or IntelliJ IDEA IDE (or any other IDE that you are using). The sample projects use Maven 3.x build tool for building the project; therefore, you’ll find a pom.xml file inside each of the projects. A pom.xml file is also provided at the root of the source code distribution, which builds all the projects. Refer appendix A to see the steps required for importing and running the sample projects. Refer to code examples Each example listing specifies the sample project name (using Project label) and the location of the source file (using Source location label). If the Project and Source location labels are not specified, you can assume that the code shown in the example listing is not being used anywhere in the sample projects, and it has been shown purely to simplify understanding. Conventions used in this book Italics has been used for emphasizing terms Comic Sans MS has been used for example listings, Java code, configuration details in XML and properties files Comic Sans MS has been used in example listings to highlight important parts of the code or configuration
  • 20.
    A NOTE highlightsan importaint point. Feedback and questions You can post your feedback and questions to the authors in the following Google Groups forum: https://groups.google.com/forum/#!forum/getting-started-with- spring-framework About the authors Ashish Sarin is a Sun Certified Enterprise Architect with more than 14 years of experience in architecting applications. He is the author of Spring Roo 1.1 Cookbook (by Packt Publishing) and Portlets in Action (by Manning Publications) J Sharma is a freelance Java developer with extensive experience in developing Spring applications.
  • 21.
    Chapter 1 –Introduction to Spring Framework
  • 22.
    1-1 Introduction In thetraditional Java enterprise application development efforts, it was a developer’s responsibility to create well-structured, maintainable and easily testable applications. The developers used myriad design patterns to address these non-business requirements of an application. This not only led to low developer productivity, but also adversely affected the quality of developed applications. Spring Framework (or ‘Spring’ in short) is an open source application framework from SpringSource (http://www.springsource.org) that simplifies developing Java enterprise applications. It provides the infrastructure for developing well-structured, maintainable and easily testable applications. When using Spring Framework, a developer only needs to focus on writing the business logic of the application, resulting in improved developer productivity. You can use Spring Framework to develop standalone Java applications, web applications, applets, or any other type of Java application. This chapter starts off with an introduction to Spring Framework modules and its benefits. At the heart of Spring Framework is its Inversion of Control (IoC) container, which provides dependency injection (DI) feature. This chapter introduces Spring’s DI feature and IoC container, and shows how to develop a standalone Java application using Spring. Towards the end of this chapter, we’ll look at some of the SpringSource’s projects that use Spring Framework as their foundation. This chapter will set the stage for the remaining chapters that delve deeper into the Spring Framework. NOTE In this book, we’ll use an example Internet Banking application, MyBank, to introduce Spring Framework features.
  • 23.
    1-2 Spring Frameworkmodules Spring Framework consists of multiple modules that are grouped based on the application development features they address. The following table describes the different module groups in Spring Framework: Module group Description Core container Contains modules that form the foundation of Spring Framework. The modules in this group provide Spring’s DI feature and IoC container implementation. AOP and instrumentation Contains modules that support AOP (Aspect-oriented Programming) and class instrumentation. Data Access/Integration Contains modules that simplify interaction with databases and messaging providers. This module group also contains modules that support programmatic and declarative transaction management, and object/XML mapping implementations, like JAXB and Castor. Web Contains modules that simplify developing web and portlet applications. Test Contains a single module that simplifies creating unit and integration tests. The above table shows that Spring covers every aspect of enterprise application development; you can use Spring for developing web applications, accessing databases, managing transactions, creating unit and integration tests, and so on. The Spring Framework modules are designed in such a way that you only need to include the modules that your application needs. For instance, to use Spring’s DI feature in your application, you only need to include the modules grouped under Core container. As you progress through this book, you’ll find details of some of the modules that are part of Spring, and examples that show how they are used in developing applications. The following figure shows the inter-dependencies of different modules of Spring:
  • 24.
    Figure 1-1 Springmodules inter-dependencies You can infer from the above figure that the modules contained in the Core container group are central to the Spring Framework, and other modules depend on it. Equally important are the modules contained in the AOP and instrumentation group because they provide AOP features to other modules in the Spring Framework. Now, that you have some basic idea about the areas of application development covered by Spring, let’s look at the Spring IoC container.
  • 25.
    1-3 Spring IoCcontainer A Java application consists of objects that interact with each other to provide application behavior. The objects with which an object interacts are referred to as its dependencies. For instance, if an object X interacts with objects Y and Z, then Y and Z are dependencies of object X. DI is a design pattern in which the dependencies of an object are typically specified as arguments to its constructor and setter methods. And, these dependencies are injected into the object when it’s created. In a Spring application, Spring IoC container (also referred to as Spring container) is responsible for creating application objects and injecting their dependencies. The application objects that the Spring container creates and manages are referred as beans. As the Spring container is responsible for putting together application objects, you don’t need to implement design patterns, like Factory, Service Locator, and so on, to compose your application. DI is also referred to as Inversion of Control (IoC) because the responsibility of creating and injecting dependencies is not with the application object but with the Spring container. Let’s say that the MyBank application (which is the name of our sample application) contains two objects, FixedDepositController and FixedDepositService. The following example listing shows that the FixedDepositController object depends on FixedDepositService object: Example listing 1-1: FixedDepositController class public class FixedDepositController { private FixedDepositService fixedDepositService; public FixedDepositController() { fixedDepositService = new FixedDepositService(); } public boolean submit() { //-- save the fixed deposit details fixedDepositService.save(.....); }
  • 26.
    } In the aboveexample listing, FixedDepositController’s constructor creates an instance of FixedDepositService which is later used in FixedDepositController’s submit method. As FixedDepositController interacts with FixedDepositService, FixedDepositService represents a dependency of FixedDepositController. To configure FixedDepositController as a Spring bean, you first need to modify the FixedDepositController class of example listing 1-1 such that it accepts FixedDepositService dependency as a constructor argument or as a setter method argument. The following example listing shows the modified FixedDepositController class: Example listing 1-2: FixedDepositController class – FixedDepositService is passed as a constructor argument public class FixedDepositController { private FixedDepositService fixedDepositService; public FixedDepositController(FixedDepositService fixedDepositService) { this.fixedDepositService = fixedDepositService; } public boolean submit() { //-- save the fixed deposit details fixedDepositService.save(.....); } } The above example listing shows that the FixedDepositService instance is now passed as a constructor argument to the FixedDepositController instance. Now, the FixedDepositService class can be configured as a Spring bean. Notice that the FixedDepositController class doesn’t implement or extend from any Spring interface or class. For a given application, information about application objects and their dependencies is specified using configuration metadata. Spring IoC container reads application’s configuration metadata to instantiate application objects and inject their dependencies. The following example listing shows the configuration metadata (in XML format) for an application that consists of MyController and
  • 27.
    MyService classes: Example listing1-3: Configuration metadata <beans .....> <bean id="myController" class="sample.spring.controller.MyController"> <constructor-arg index="0" ref="myService" /> </bean> <bean id="myService" class="sample.spring.service.MyService"/> </beans> In the above example listing, each <bean> element defines an application object that is managed by the Spring container, and the <constructor-arg> element specifies that an instance of MyService is passed as an argument to MyController’s constructor. The <bean> element is discussed in detail later in this chapter, and the <constructor-arg> element is discussed in chapter 2. Spring container reads the configuration metadata (like the one shown in example listing 1-3) of an application and creates the application objects defined by <bean> elements and injects their dependencies. Spring container makes use of Java Reflection API (http://docs.oracle.com/javase/tutorial/reflect/index.html) to create application objects and inject their dependencies. The following figure summarizes how the Spring container works: Figure 1-2 Spring container reads application’s configuration metadata and creates a fully-configured application
  • 28.
    The configuration metadatacan be supplied to the Spring container via XML (as shown in example listing 1-3), Java annotations (refer chapter 6) and also through the Java code (refer chapter 6). As the Spring container is responsible for creating and managing application objects, enterprise services (like transaction management, security, remote access, and so on) can be transparently applied to the objects by the Spring container. The ability of the Spring container to enhance the application objects with additional functionality makes it possible for you to model your application objects as simple Java objects (also referred to as POJOs or Plain Old Java Objects). Java classes corresponding to POJOs are referred to as POJO classes, which are nothing but Java classes that don’t implement or extend framework- specific interfaces or classes. The enterprise services, like transaction management, security, remote access, and so on, required by these POJOs are transparently provided by the Spring container. Now, that we know how Spring container works, let’s look at some examples that demonstrate benefits of developing applications using Spring.
  • 29.
    1-4 Benefits ofusing Spring Framework In the previous section, we discussed the following benefits of using Spring: § Spring simplifies composing Java applications by taking care of creating application objects and injecting their dependencies § Spring promotes developing applications as POJOs Spring also simplifies interaction with JMS providers, JNDI, MBean servers, email servers, databases, and so on, by providing a layer of abstraction that takes care of the boilerplate code. Let’s take a quick look at a few examples to better understand the benefits of developing applications using Spring. Consistent approach to managing local and global transactions If you are using Spring for developing transactional applications, you can use Spring’s declarative transaction management support to manage transactions. The following example listing shows the FixedDepositService class of MyBank application: Example listing 1-4 – FixedDepositService class public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } The FixedDepositService class is a POJO class that defines methods to create and retrieve details of fixed deposits. The following figure shows the form for creating a new fixed deposit:
  • 30.
    Figure 1-3 HTMLform for creating a new fixed deposit A customer enters the fixed deposit amount, tenure and email id information in the above form and clicks the Save button to create a new fixed deposit. The FixedDepositService’s createFixedDeposit method (refer example listing 1-1) is invoked to create the fixed deposit. The createFixedDeposit method debits the amount entered by the customer from his bank account, and creates a fixed deposit of the same amount. Let’s say that information about the bank balance of customers is stored in BANK_ACCOUNT_DETAILS database table, and the fixed deposit details are stored in FIXED_DEPOSIT_DETAILS database table. If a customer creates a fixed deposit of amount x, amount x is subtracted from the BANK_ACCOUNT_DETAILS table, and a new record is inserted in FIXED_DEPOSIT_DETAILS table to reflect the newly created fixed deposit. If BANK_ACCOUNT_DETAILS table is not updated or a new record is not inserted in FIXED_DEPOSIT_DETAILS table, it’ll leave the system in an inconsistent state. This means the createFixedDeposit method must be executed within a transaction. The database used by the MyBank application represents a transactional resource. In the traditional approach to perform a set of database modifications as a single unit of work, you’ll first disable auto-commit mode of JDBC connection, then execute SQL statements, and finally commit (or rollback) the transaction. The following example listing shows how to manage database transactions in the createFixedDeposit method using the traditional approach: Example listing 1-5 – Programmatically managing database transaction using JDBC Connection object
  • 31.
    import java.sql.Connection; import java.sql.SQLException; publicclass FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { Connection con = ..... ; try { con.setAutoCommit(false); //-- execute SQL statements that modify database tables con.commit(); } catch(SQLException sqle) { if(con != null) { con.rollback(); } } ..... } } The above example listing shows that the createFixedDeposit method programmatically manages database transaction using JDBC Connection object. This approach is suitable for application scenarios in which a single database is involved. Transactions that are resource-specific, like the transaction associated with a JDBC Connection, are referred to as local transactions. When multiple transactional resources are involved, JTA (Java Transaction API) is used for managing transactions. For instance, if you want to send a JMS message to a messaging middleware (a transactional resource) and update a database (another transactional resource) in the same transaction, you must use a JTA transaction manager to manage transactions. JTA transactions are also referred to as global (or distributed) transactions. To use JTA, you fetch UserTransaction object (which is part of JTA API) from JNDI and programmatically start and commit (or rollback) transactions. As you can see, you can either use JDBC Connection (for local transactions) or
  • 32.
    UserTransaction (for globaltransactions) object to programmatically manage transactions. It is important to note that a local transaction cannot run within a global transaction. This means that if you want database updates in createFixedDeposit method (refer example listing 1-5) to be part of a JTA transaction, you need to modify the createFixedDeposit method to use the UserTransaction object for transaction management. Spring simplifies transaction management by providing a layer of abstraction that gives a consistent approach to managing both local and global transactions. This means that if you write the createFixedDeposit method (refer example listing 1-5) using Spring’s transaction abstraction, you don’t need to modify the method when you switch from local to global transaction management, or vice versa. Spring’s transaction abstraction is explained in chapter 7. Declarative transaction management Spring gives you the option to use declarative transaction management. You can annotate a method with Spring’s @Transactional annotation and let Spring handle transactions, as shown here: Example listing 1-6 – @Transactional annotation usage import org.springframework.transaction.annotation.Transactional; public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } @Transactional public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } The above example listing shows that the FixedDepositService class doesn’t implement or extend from any Spring-specific interface or class to use Spring’s transaction management facility. The Spring Framework transparently provides transaction management feature to @Transactional annotated createFixedDeposit method. This shows that Spring is a non-invasive framework because it doesn’t require your application objects to be dependent upon Spring- specific classes or interfaces. Also, you don’t need to directly work with
  • 33.
    transaction management APIsto manage transactions. Security Security is an important aspect of any Java application. Spring Security (http://static.springsource.org/spring-security/site/) is a SpringSource’s project that is built on top of Spring Framework. Spring Security provides authentication and authorization features that you can use for securing Java applications. Let’s say that the following 3 user roles have been identified for the MyBank application: LOAN_CUSTOMER, SAVINGS_ACCOUNT_CUSTOMER and APPLICATION_ADMIN. A customer must be associated with the SAVINGS_ACCOUNT_CUSTOMER or the APPLICATION_ADMIN role to invoke the createFixedDeposit method of FixedDepositService class (refer example listing 1-6). Using Spring Security you can easily address this requirement by annotating createFixedDeposit method with Spring Security’s @Secured annotation, as shown in the following example listing: Example listing 1-7 – Secured createFixedDeposit method import org.springframework.transaction.annotation.Transactional; import org.springframework.security.access.annotation.Secured; public class FixedDepositService { public FixedDepositDetails getFixedDepositDetails( ..... ) { ..... } @Transactional @Secured({ "SAVINGS_ACCOUNT_CUSTOMER", "APPLICATION_ADMIN" }) public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } If you annotate a method with Spring Security’s @Secured annotation, security feature is transparently applied to the method by the Spring Security framework. The above example listing shows that for implementing method-level security you don’t need to extend or implement any Spring-specific classes or interfaces. Also, you don’t need to write security-related code in your business methods.
  • 34.
    Spring Security frameworkis discussed in detail in chapter 14. JMX (Java Management Extensions) Spring’s JMX support simplifies incorporating JMX technology in your applications. Let’s say that the fixed deposit facility of MyBank application should only be available to customers from 9:00 AM to 6:00 PM everyday. To address this requirement, a variable is added to the FixedDepositService class, which acts as a flag indicating whether the fixed deposit service is active or inactive. The following example listing shows the FixedDepositService class that uses such a flag: Example listing 1-8 – FixedDepositService with active variable public class FixedDepositService { private boolean active; public FixedDepositDetails getFixedDepositDetails( ..... ) { if(active) { ..... } } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { if(active) { ..... } } public void activateService() { active = true; } public void deactivateService() { active = false; } } The above example listing shows that a variable named active is added to the FixedDepositService class. If the value of the active variable is true, the getFixedDepositDetails and createFixedDeposit methods work as expected. If the value of the active variable is false, the getFixedDepositDetails and createFixedDeposit methods throw an exception indicating that the fixed deposit service is currently inactive. The activateService and deactivateService methods
  • 35.
    set the valueof active variable to true and false, respectively. Now, who calls the activateService and deactivateService methods? Let’s say a separate scheduler application, Bank App Scheduler, runs at 9:00 AM and 6:00 PM to execute activateService and deactivateService methods, respectively. The Bank App Scheduler application uses JMX (Java Management Extensions) API to remotely interact with FixedDepositService instance. NOTE Refer to the following article to learn more about JMX: http://docs.oracle.com/javase/tutorial/jmx/index.html. As Bank App Scheduler uses JMX to change the value of the active variable of the FixedDepositService instance, you need to register the FixedDepositService instance as a managed bean (or MBean) with an MBean server, and expose FixedDepositService’s activateService and deactivateService methods as JMX operations. In Spring, you register instances of a class with the MBean server by annotating the class with Spring’s @ManagedResource annotation, and expose the methods of the class as JMX operations using Spring’s @ManagedOperation annotation. The following example listing shows usage of @ManagedResource and @ManagedOperation annotations to register instances of the FixedDepositService class with the MBean server, and to expose its activateService and deactivateService methods as JMX operations: Example listing 1-9 – FixedDepositService class that uses Spring’s JMX support import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; @ManagedResource(objectName = "fixed_deposit_service:name=FixedDepositService") public class FixedDepositService { private boolean active; public FixedDepositDetails getFixedDepositDetails( ..... ) { if(active) { ..... } } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails)
  • 36.
    { if(active) { .....} } @ManagedOperation public void activateService() { active = true; } @ManagedOperation public void deactivateService() { active = false; } } The above example listing shows that the FixedDepositService class doesn’t directly use JMX API to register its instances with the MBean server and to expose its methods as JMX operations. JMS (Java Message Service) Spring’s JMS support simplifies sending and receiving messages from JMS providers. In MyBank application, when a customer submits a request to receive details of their fixed deposits via email, the FixedDepositService sends the request details to a JMS messaging middleware (like ActiveMQ). The request is later processed by a message listener. Spring simplifies interaction with JMS providers by providing a layer of abstraction. The following example listing shows how FixedDepositService class sends request details to a JMS provider using Spring’s JmsTemplate: Example listing 1-10 – FixedDepositService that sends JMS messages import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; public class FixedDepositService { @Autowired
  • 37.
    private transient JmsTemplatejmsTemplate; ..... public boolean submitRequest(Request request) { jmsTemplate.convertAndSend(request); } } The above example listing shows that the FixedDepositService defines a variable of type JmsTemplate, and is annotated with Spring’s @Autowired annotation. For now, you can assume that the @Autowired annotation provides access to a JmsTemplate instance. The JmsTemplate instance knows about the JMS destination to which the JMS message is to be sent. How the JmsTemplate is configured is described in detail in chapter 8. The FixedDepositService’s submitRequest method invokes JmsTemplate’s convertAndSend method to send request details (represented by Request argument of submitRequest method) as a JMS message to the JMS provider. Once again, the above example listing shows that if you are using Spring Framework to send messages to JMS providers, then you don’t need to directly deal with JMS API. Caching Spring’s cache abstraction provides a consistent approach to use caching in your application. It’s common to use caching solutions to improve the performance of an application. MyBank application uses a caching product to improve the performance of read operations for fixed deposit details. Spring Framework simplifies interacting with different caching solutions by abstracting caching- related logic. The following example listing shows that the FixedDepositService’s getFixedDepositDetails method uses Spring’s cache abstraction feature to cache fixed deposit details: Example listing 1-11 – FixedDepositService that caches fixed deposit details import org.springframework.cache.annotation.Cacheable; public class FixedDepositService {
  • 38.
    @Cacheable("FixedDeposits") public FixedDepositDetails getFixedDepositDetails(..... ) { ..... } public boolean createFixedDeposit(FixedDepositDetails fixedDepositDetails) { ..... } } In the above example listing, Spring’s @Cacheable annotation indicates that the fixed deposit details returned by the getFixedDepositDetails method are cached. If the getFixedDepositDetails method is invoked with the same argument value(s), the getFixedDepositDetails method is not executed, and the fixed deposit details are returned from the cache. This shows that if you are using Spring Framework you don’t need to write caching-related logic in your classes. Spring’s cache abstraction is explained in detail in chapter 8. In this section, we saw that Spring Framework simplifies developing enterprise applications by transparently providing services to POJOs, thereby shielding developers from lower level API details. Spring also provides easy integration with standard frameworks, like Hibernate, iBATIS, Quartz, JSF, Struts, EJB, and so on, which makes Spring an ideal choice for enterprise application development. Now, that we have looked at some of the benefits of using Spring Framework, let’s take a look at how to develop a simple Spring application.
  • 39.
    1-5 A simpleSpring application In this section, we’ll look at a simple Spring application that uses Spring’s DI feature. To use Spring’s DI feature in an application, follow these steps: 1. identify application objects and their dependencies 2. create POJO classes corresponding to the application objects identified in step 1 3. create configuration metadata that depicts application objects and their dependencies 4. create an instance of Spring IoC container and pass the configuration metadata to it 5. access application objects from the Spring IoC container instance Let’s now look at above mentioned steps in the context of MyBank application. Identifying application objects and their dependencies We discussed earlier that the MyBank application shows a form for creating a fixed deposit (refer figure 1-3) to its users for creating a fixed deposit. The following sequence diagram shows the application objects (and their interaction) that come into picture when the user submits the form: Figure 1-4 MyBank’s application objects and their dependencies In the above sequence diagram, FixedDepositController represents a web controller that receives the request when the form is submitted. The fixed deposit
  • 40.
    details are containedin the FixedDepositDetails object. The FixedDepositController invokes the createFixedDeposit method of FixedDepositService (a service layer object). Then, FixedDepositService invokes FixedDepositDao object (a data access object) to save the fixed deposit details in the application’s data store. So, we can interpret from the above diagram that FixedDepositService is a dependency of FixedDepositController object, and FixedDepositDao is a dependency of FixedDepositService object. IMPORT chapter 1/ch01-bankapp-xml (This project shows a simple Spring application that uses Spring’s DI feature. To run the application, execute the main method of the MyBankApp class of this project) Creating POJO classes corresponding to identified application objects Once you have identified application objects, the next step is to create POJO classes corresponding to these application objects. POJO classes corresponding to the FixedDepositController, FixedDepositService and FixedDepositDao application objects are available in ch01-bankapp-xml project. The ch01- bankapp-xml project represents a simplified version of MyBank application that uses Spring’s DI feature. You should import the ch01-bankapp-xml project into your IDE as in the remaining steps we’ll be looking at the files contained in this project. In section 1-3 we discussed that a dependency is passed to an application object as a constructor argument or as a setter method argument. The following code listing shows that an instance of FixedDepositService (a dependency of FixedDepositController) is passed as a setter method argument to the FixedDepositController object: Example listing 1-12 – FixedDepositController class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; ..... public class FixedDepositController { ..... private FixedDepositService fixedDepositService;
  • 41.
    ..... public void setFixedDepositService(FixedDepositService fixedDepositService){ logger.info("Setting fixedDepositService property"); this.fixedDepositService = fixedDepositService; } ..... public void submit() { fixedDepositService.createFixedDeposit(new FixedDepositDetails( 1, 10000, 365, "someemail@something.com")); } ..... } In the above example listing, FixedDepositService dependency is passed to FixedDepositController through setFixedDepositService method. We’ll soon see that the setFixedDepositService setter method is invoked by Spring. NOTE If you look at the FixedDepositController, FixedDepositService and FixedDepositDao classes, you’ll notice that none of these classes implement any Spring-specific interface or extend from any Spring-specific class. Let’s now look at how application objects and their dependencies are specified in the configuration metadata. Creating the configuration metadata We saw in section 1-3 that the configuration metadata specifies application objects and their dependencies, which is read by the Spring container to instantiate application objects and inject their dependencies. In this section, we’ll first look at what other information is contained in the configuration metadata, followed by an in-depth look at how configuration metadata is specified in XML format. The configuration metadata specifies information about the enterprise services (like transaction management, security and remote access) that are required by the application. For instance, if you want Spring to manage transactions, you need to configure an implementation of Spring’s PlatformTransactionManager interface in the configuration metadata. The PlatformTransactionManager
  • 42.
    implementation is responsiblefor managing transactions (refer chapter 7 to know more about Spring’s transaction management feature). If your application interacts with messaging middlewares (like ActiveMQ), databases (like MySQL), e-mail servers, and so on, then Spring-specific objects that simplify interacting with these external systems are also defined in the configuration metadata. For instance, if your application sends or receives JMS messages from ActiveMQ, then you can configure Spring’s JmsTemplate class in the configuration metadata to simplify interaction with ActiveMQ. We saw in example listing 1-10 that if you use JmsTemplate for sending messages to a JMS provider, then you don’t need to deal with lower-level JMS API (refer chapter 8 to know more about Spring’s support for interacting with JMS providers). You can supply the configuration metadata to the Spring container via an XML file or through annotations in POJO classes. Starting with Spring 3.0, you can also supply the configuration metadata to the Spring container through Java classes annotated with Spring’s @Configuration annotation. In this section, we’ll see how configuration metadata is specified in XML format. In chapter 6, we’ll see how configuration metadata is supplied via annotations in POJO classes and through @Configuration annotated Java classes. You provide the configuration metadata for an application in XML format by creating an application context XML file that contains information about the application objects and their dependencies. Example listing 1-3 showed how an application context XML file looks like. The following XML shows the application context XML file of MyBank application that consists of FixedDepositController, FixedDepositService and FixedDepositDao objects (refer figure 1-4 to see how these objects interact with each other): Example listing 1-13 – applicationContext.xml - MyBank’s application context XML file Project – ch01-bankapp-xml Source location - src/main/resources/META-INF/spring <?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
  • 43.
    <bean id="controller" class="sample.spring.chapter01.bankapp.FixedDepositController"> <property name="fixedDepositService"ref="service" /> </bean> <bean id="service" class="sample.spring.chapter01.bankapp.FixedDepositService"> <property name="fixedDepositDao" ref="dao" /> </bean> <bean id="dao" class="sample.spring.chapter01.bankapp.FixedDepositDao"/> </beans> The following are the important points to note about the application context XML file shown above: · The <beans> element is the root element of the application context XML file, and is defined in spring-beans-4.0.xsd schema (also referred to as Spring’s beans schema). The spring-beans-4.0.xsd schema is contained in spring-beans-4.0.0.RELEASE.jar JAR file that comes with the Spring Framework distribution. · Each <bean> element configures an application object that is managed by the Spring container. In Spring Framework’s terminology, a <bean> element represents a bean definition. The object that the Spring container creates based on the bean definition is referred to as a bean. The id attribute specifies a unique name for the bean, and the class attribute specifies the fully-qualified class name of the bean. You can also use the name attribute of <bean> element to specify aliases for the bean. In MyBank application, the application objects are FixedDepositController, FixedDepositService and FixedDepositDao; therefore, we have 3 <bean> elements - one for each application object. As application objects configured by <bean> elements are managed by the Spring container, the responsibility for creating them and injecting their dependencies is with the Spring container. Instead of directly creating instances of application objects defined by <bean> elements, you should obtain them from the
  • 44.
    Spring container. Laterin this section, we’ll look at how to obtain application objects managed by Spring container. · No <bean> element is defined corresponding to the FixedDepositDetails domain object of MyBank application. This is because domain objects are not typically managed by the Spring container; they are created by the ORM framework (like Hibernate) used by the application, or you create them programmatically using the new operator. · The <property> element specifies a dependency (or a configuration property) of the bean configured by the <bean> element. The <property> element corresponds to a JavaBean-style setter method in the bean class which is invoked by the Spring container to set a dependency (or a configuration property) of the bean. Let’s now look at how dependencies are injected via setter methods. Injecting dependencies via setter methods To understand how dependencies are injected via setter methods defined in the bean class, let’s once again look at the FixedDepositController class of MyBank application: Example listing 1-14 – FixedDepositController class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; import org.apache.log4j.Logger; public class FixedDepositController { private static Logger logger = Logger.getLogger(FixedDepositController.class); private FixedDepositService fixedDepositService; public FixedDepositController() { logger.info("initializing");
  • 45.
    } public void setFixedDepositService(FixedDepositService fixedDepositService){ logger.info("Setting fixedDepositService property"); this.fixedDepositService = fixedDepositService; } ..... } The above example listing shows that the FixedDepositController class declares an instance variable named fixedDepositService of type FixedDepositService. The fixedDepositService variable is set by the setFixedDepositService method - a JavaBean-style setter method for fixedDepositService variable. This is an example of setter-based DI, wherein a setter method satisfies a dependency. The following figure describes the bean definition for the FixedDepositController class in the applicationContext.xml file (refer example listing 1-13): Figure 1-5 Defining dependencies using <property> elements The above bean definition shows that the FixedDepositController bean defines its dependence on FixedDepositService bean via <property> element. The <property> element’s name attribute corresponds to the JavaBean-style setter method in the bean class that is invoked by the Spring container at the time of bean creation. The <property> element’s ref attribute identifies the Spring bean whose instance needs to be created and passed to the JavaBean-style setter
  • 46.
    method. The valueof ref attribute must match the id attribute’s value (or one of the names specified by the name attribute) of a <bean> element in the configuration metadata. In figure 1-5, the value of <property> element’s name attribute is fixedDepositService, which means that the <property> element corresponds to the setFixedDepositService setter method of FixedDepositController class (refer example listing 1-14). As the value of <property> element’s ref attribute is service, the <property> element refers to the <bean> element whose id attribute’s value is service. Now, the <bean> element whose id attribute’s value is service is the FixedDepositService bean (refer example listing 1-13). Spring container creates an instance of FixedDepositService class (a dependency), and invokes the setFixedDepositService method (a JavaBean-style setter method for fixedDepositService variable) of FixedDepositController (a dependent object), passing the FixedDepositService instance. In the context of FixedDepositController application object, the following figure summarizes the purpose of name and ref attributes of <property> element: Figure 1-6 <property> element’s name attribute corresponds to a JavaBean-style setter method that satisfies a bean dependency, and ref attribute refers to another
  • 47.
    bean. The above figureshows that fixedDepositService value of name attribute corresponds to the setFixedDepositService method of FixedDepositController class, and service value of ref attribute refers to the bean whose id is service. NOTE It is fairly common to refer to a bean definition by its name (which is id attribute’s value) or type (which is class attribute’s value) or the interface implemented by the bean class. For instance, you can refer to ‘FixedDepositController bean’ as ‘controller bean’. And, if the FixedDepositController class implements FixedDepositControllerIntf interface, you can refer to ‘FixedDepositController bean’ as ‘FixedDepositControllerIntf bean’. The following diagram summarizes how the Spring container creates beans and injects their dependencies based on the configuration metadata supplied by the applicationContext.xml file (refer example listing 1-13) of MyBank application: Figure 1-7 - The sequence in which Spring IoC container creates beans and injects their dependencies. The above figure shows the sequence of steps followed by the Spring IoC container to create FixedDepositController, FixedDepositService and FixedDepositDao beans and inject their dependencies. Before attempting to create beans, the Spring container reads and validates the configuration metadata supplied by the applicationContext.xml file. The order in which the beans are
  • 48.
    created by theSpring container depends on the order in which they are defined in the applicationContext.xml file. Spring container ensures that the dependencies of a bean are completely configured before the setter method is invoked. For example, the FixedDepositController bean is dependent on FixedDepositService bean; therefore, Spring container configures the FixedDepositService bean before invoking the setFixedDepositService method of FixedDepositController bean. The bean definitions that we have seen so far, instruct Spring container to create bean instances by invoking the no-argument constructor of the bean class, and inject dependencies using setter-based DI. In chapter 2, we’ll look at bean definitions that instruct Spring container to create a bean instance via a factory method defined in a class. Also, we’ll look at how to inject dependencies through constructor arguments (referred to as constructor-based DI), through arguments to the factory method that creates the bean instance, and by using setter-based DI on the bean instance returned by the factory method. Let’s now look at how to create an instance of Spring container and pass configuration metadata to it. Creating an instance of Spring container Spring’s ApplicationContext object represents an instance of Spring container. Spring provides a few built-in implementations of ApplicationContext interface, like ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, XmlWebApplicationContext, XmlPortletApplicationContext, and so on. The choice of the ApplicationContext implementation depends on how you have defined the configuration metadata (using XML, annotations or Java code), and the type of your application (standalone, web or portlet application). For instance, ClassPathXmlApplicationContext and FileSystemXmlApplicationContext classes are suitable for standalone applications in which configuration metadata is supplied in XML format, XmlWebApplicationContext is suitable for web applications in which the configuration metadata is supplied in XML format, AnnotationConfigWebApplicationContext is suitable for web applications in which configuration metadata is supplied through Java code, and so on. As MyBank application represents a standalone application, we can use either ClassPathXmlApplicationContext or FileSystemXmlApplicationContext class to
  • 49.
    create an instanceof Spring container. You should note that the ClassPathXmlApplicationContext class loads an application context XML file from the specified classpath location, and the FileSystemXmlApplicationContext class loads an application context XML file from the specified location on the filesystem. The following BankApp class of MyBank application shows that an instance of Spring container is created using the ClassPathXmlApplicationContext class: Example listing 1-15 – BankApp class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class BankApp { ..... public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/applicationContext.xml"); ..... } } The above example listing shows the BankApp’s main method, which is responsible for bootstrapping the Spring container. The classpath location of the application context XML file is passed to the constructor of ClassPathXmlApplicationContext class. The creation of ClassPathXmlApplicationContext instance results in creation of those beans in the application context XML file that are singleton-scoped and set to be pre- instantiated. In chapter 2, we’ll discuss bean scopes, and what it means to have beans pre- or lazily-instantiated by Spring container. For now, you can assume that the beans defined in the applicationContext.xml file of MyBank application are singleton-scoped and set to be pre-instantiated. This means that the beans
  • 50.
    defined in theapplicationContext.xml file are created when an instance of ClassPathXmlApplicationContext is created. Now, that we have seen how to create an instance of the Spring container, let’s look at how to retrieve bean instances from the Spring container. Access beans from the Spring container The application objects defined via <bean> elements are created and managed by the Spring container. You can access instances of these application objects by calling one of the getBean methods of the ApplicationContext interface. The following example listing shows the main method of BankApp class that retrieves an instance of FixedDepositController bean from the Spring container and invokes its methods: Example listing 1-16 – BankApp class Project – ch01-bankapp-xml Source location - src/main/java/sample/spring/chapter01/bankapp package sample.spring.chapter01.bankapp; import org.apache.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class BankApp { private static Logger logger = Logger.getLogger(BankApp.class); public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/applicationContext.xml"); FixedDepositController fixedDepositController = (FixedDepositController) context.getBean("controller"); logger.info("Submission status of fixed deposit : " + fixedDepositController.submit()); logger.info("Returned fixed deposit info : " + fixedDepositController.get());
  • 51.
    } } At first, theApplicationContext’s getBean method is invoked to retrieve an instance of FixedDepositController bean from the Spring container, followed by invocation of submit and get methods of FixedDepositController bean. The argument passed to the getBean method is the name of the bean whose instance you want to retrieve from the Spring container. The name of the bean passed to the getBean method must be the value of the id or name attribute of the bean that you want to retrieve. If no bean with the specified name is registered with the Spring container, an exception is thrown by the getBean method. In example listing 1-16, to configure the FixedDepositController instance, we didn’t programmatically create an instance of FixedDepositService and set it on the FixedDepositController instance. Also, we didn’t create an instance of FixedDepositDao and set it on the FixedDepositService instance. This is because the task of creating dependencies, and injecting them into the the dependent objects is handled by the Spring container. If you go to ch01-bankapp-xml project and execute the main method of BankApp class, you’ll see the following output on the console: INFO sample.spring.chapter01.bankapp.FixedDepositController - initializing INFO sample.spring.chapter01.bankapp.FixedDepositService - initializing INFO sample.spring.chapter01.bankapp.FixedDepositDao - initializing INFO sample.spring.chapter01.bankapp.FixedDepositService - Setting fixedDepositDao property INFO sample.spring.chapter01.bankapp.FixedDepositController - Setting fixedDepositService property INFO sample.spring.chapter01.bankapp.BankApp - Submission status of fixed deposit : true INFO sample.spring.chapter01.bankapp.BankApp - Returned fixed deposit info : id :1, deposit amount : 10000.0, tenure : 365, email : someemail@something.com The above output shows that Spring container creates an instance of each of the beans defined in the applicationContext.xml file of MyBank application. Also, Spring container uses setter-based DI to inject an instance of FixedDepositService into FixedDepositController instance, and an instance of FixedDepositDao into the FixedDepositService instance. Let’s now look at some of the frameworks that are built on top of Spring Framework.
  • 52.
    1-6 Frameworks builton top of Spring Though there are many frameworks from SpringSource that use Spring Framework as the foundation, we’ll look at some of the widely popular ones. For a more comprehensive list of frameworks, and for more details about an individual framework, it’s recommended that you visit the SpringSource website (www.springsource.org). The following table provides a high-level overview of the frameworks from SpringSource that are built on top of Spring Framework: Framework Description Spring Security Authentication and authorization framework for enterprise applications. You need to configure a few beans in your application context XML file to incorporate authentication and authorization features into your application. Spring Data Provides a consistent programming model to interact with different types of databases. For instance, you can use it to interact with non-relational databases, like MongoDB or Neo4j, and you can also use it for accessing relational databases using JPA. Spring Batch If your application requires bulk processing, this framework is for you. Spring Integration Provides Enterprise Application Integration (EAI) capabilities to applications. Spring Social If your application requires interaction with social media websites, like Facebook and Twitter, then you’ll find this framework highly useful. Spring BlazeDS Integration If you are developing an Adobe Flex based application, you can use this framework to connect Flex frontend with Spring-based business tier. As the frameworks mentioned in the above table are built on top of Spring Framework, before using any of these frameworks make sure that they are compatible with the Spring Framework version that you are using.
  • 53.
    1-7 Summary In thischapter, we looked at the benefits of using Spring Framework. We also looked at a simple Spring application that showed how to specify configuration metadata in XML format, create the Spring container instance and retrieve beans from it. In the next chapter, we’ll look at some of the foundation concepts of Spring Framework.
  • 54.
    Chapter 2 –Spring Framework basics
  • 55.
    Another Random Documenton Scribd Without Any Related Topics
  • 56.
    miracles occurred, thatits later opponents should have given up this strong line of defence, and have adopted the far weaker one that they did occur, but were due to magic. We are quite justified, then, in saying that Christ's miracles were not disputed at the time, and considering their alleged publicity, this is a strong additional argument in their favour. [360] Origen cont. Cels., i. 38; ii. 48. (4.) The silence of classical writers. All that can be said on the other side is from the silence of classical writers. Had the miracles really occurred, it is said, especially in such a well-known place as Palestine, the writers of the day would have been full of them. Yet, with the single exception of Tacitus, they do not even allude to Christianity; and he dismisses it with contempt as a pernicious superstition.[361] [361] Tacitus Annals. Bk. xv., ch. 44. Now these words of Tacitus show that he had never studied the subject, for whatever may be said against the religion, it certainly was not pernicious; so he must have rejected Christianity without examination. And if the other classical writers did the same, there is nothing remarkable in their not alluding to it. Alleged marvels were common enough in those days, and they probably did not think the Christian miracles worth inquiring about. But we do not know of any writer who did inquire about them, and was not convinced of their truth. It may, of course, be replied that some of the events ought anyhow to be alluded to, such as the darkness over all the land at the time of the Crucifixion. And if this extended over the whole of Palestine, it is certainly strange that it should not be noticed. But it may only refer to the neighbourhood of Jerusalem. Compare the expression all the country of Judæa[362] (when referring to the people being baptized) which is evidently not meant to be taken literally. And if the darkness was limited to the neighbourhood of Jerusalem, there
  • 57.
    is nothing surprisingin its not being recorded by any except Christians, for whom of course it had a special significance. [362] Mark 1. 5. It should also be noticed that in some respects the testimony of Christian writers is more valuable than that of either Jews or Gentiles: since none of the writers of that country were brought up as Christians. They were all unbelievers before they were believers; and if such testimony from unbelievers would be valuable, it is still more so from those who showed how thoroughly convinced they were of its truth by becoming believers. Indeed, the best Jewish or Gentile evidence conceivable is that of well-educated men, like St. Paul and St. Luke, who, on the strength of it, became Christians. Lastly, it must be remembered that the argument from silence is proverbially unsound. We have, for instance, over two hundred letters of the younger Pliny, and in only one of these does he mention Christianity. Suppose this one had been lost, what a strong argument could have been formed against the spread of Christianity from the silence of Pliny, yet this one shows its marvellous progress (see Chapter XXII.). This objection, then, is quite insufficient to outweigh the positive testimony in favour of the miracles, to which we have already alluded. (D.) Conclusion. In conclusion we must notice certain rationalistic explanations which have been given of the miracles. It was hardly to be expected that, with such strong evidence in their favour, the modern opponents of Christianity would merely assert that the accounts were pure fiction from beginning to end. Attempts have of course been made to explain the miracles in such a way that, while depriving them of any supernatural character, it may yet be admitted that some such events occurred, which gave rise to the Christian accounts. The miracles of healing are perhaps the easiest to explain in this way, as some wonderful instances of sudden, though natural, cures
  • 58.
    have been known.But it is doubtful whether any of Christ's miracles were of such a kind, for St. Paul is careful to distinguish between gifts of healing and working of miracles.[363] Both were evidently known to the early Church, and known to be different. [363] 1 Cor. 12. 9-10, 28. And of course no such explanations will apply to most of the miracles, which have to be got rid of in various other ways. Thus Christ's walking on the sea is explained as His walking on a ridge of sand or rock running out just under the water; the raising of Lazarus as his having had himself buried alive, so that when Christ came, there might be a pretended miracle;[364] and feeding the five thousand as nothing more than the example of Christ and His friends, who so freely shared their small supply with those around them, that others did the same, and thus everyone had a little. It seems scarcely necessary to discuss these theories in detail, as they are all most improbable. [364] This extraordinary theory was maintained by Rénan in the earlier editions of his Life of Jesus, though he afterwards abandoned it. Moreover, their difficulties are all cumulative. The Christian explanation has but one difficulty for all the miracles, which is that they are miracles, and involve the supernatural. Once admit this, and twenty miracles (provided they occur on suitable occasions) are no more difficult to believe than two. But the difficulties of these explanations are all cumulative. If for instance, the raising of Lazarus is explained by his having been buried alive, it does not account for Christ's walking on the sea. If this is explained by the supposed ridge of sand, it does not account for feeding the five thousand, etc. Thus each difficulty has to be added to all the others, so taken together they are quite insuperable. One other point has still to be considered, which is the subject of modern miracles. Why, it is said, are there no miracles now, when they could be properly tested? If they were really employed by God as helps to the spread of His religion, why should they not have
  • 59.
    accompanied it atintervals all along, as it is said they did the Jewish religion? They are surely wanted for the support of Christianity at the present day; and if God were, after due warning, to work a public and indisputable miracle every half-century, all the other evidences of Christianity might be dispensed with. The answer to this objection is that the Christian revelation does not claim to be a gradual one, like the Jewish; but a final and complete revelation, made once for all through Christ and His Apostles. Therefore, as there is to be no fresh revelation, there can be no fresh miracles to confirm it. The question of other miracles, such as those which are said to have been worked by Christians at various periods, need not be considered here. If true, they would of course tend to prove the New Testament ones; while, if untrue, they would not disprove them, any more than imitation diamonds would disprove the existence of real diamonds. Of course, it may be replied that God might still work a miracle now by a man, who stated that it was not to confirm anything that he said himself, but merely what the Founder of Christianity had said; and this is no doubt possible. But it would be a different method from that recorded in the Bible, where a messenger from God always brings his own credentials, even though, as in the case of a prophecy, they may not be verified till afterwards. And what reason have we for thinking that God would change His method now? It is also very doubtful whether a public miracle at the present day, would convince everybody. This objection, then, must be put aside, and we therefore conclude, on reviewing the whole subject, that the New Testament miracles are not only credible, but that there is extremely strong evidence in their favour. Indeed their marks of truthfulness, combined with their alleged publicity, form together a very powerful argument. And it is rendered all the stronger by their having been so thoroughly successful. Their object was to establish the truth of Christianity, and this is precisely what they did. The evidence they afforded was so decisive, that a hostile world found it irresistible.
  • 60.
    Moreover it isdoubtful whether any other religion, except, of course, the Jewish, has ever claimed to have been confirmed by public miracles. Christianity thus rests upon a unique foundation. Unlike other religions, it appealed at first not to abstract reasoning, or moral consciousness, or physical force, but to miraculous events, of the truth or falsehood of which others could judge. They did judge, and they were convinced. We decide, then, that the New Testament miracles are probably true.
  • 61.
    CHAPTER XX. THAT THEJEWISH PROPHECIES CONFIRM THE TRUTH OF CHRISTIANITY. (A.) Isaiah's Prophecy of the Lord's Servant. (1.) The historical agreement, very striking. (2.) The doctrinal agreement, equally so. (3.) The modern Jewish interpretation, quite untenable. (B.) The Psalm of the Crucifixion. (1.) Its close agreement, all through. (2.) Two objections, unimportant. (C.) The Divinity of the Messiah. At least three prophecies of this; it is also involved in some hints as to the Doctrine of the Trinity. (D.) Conclusion. Why are not the prophecies plainer? Cumulative nature of the evidence. We propose to consider in this chapter what is called the argument from Prophecy, using the word, as we did in Chapter XI., in the sense of prediction. Now it is a remarkable and undisputed fact that for many centuries before the time of Christ, it was foretold that a member of the Jewish nation—small and insignificant though it was —should be a blessing to all mankind. This promise is recorded as having been made both to Abraham, to Isaac, and to Jacob;[365] and as a matter of fact, Christianity was founded by a Jew, and has
  • 62.
    undoubtedly been ablessing to the human race. This is at least a remarkable coincidence. And as we proceed in the Old Testament, the statements about this future Messiah become clearer and fuller, till at last, in the Prophets, we find whole chapters referring to Him, which Christians assert were fulfilled in Christ. [365] Gen. 22. 18; 26. 4; 28.14. This argument is plainly of the utmost importance. Fortunately it is much simplified by the question of dates being altogether excluded. As a rule, the most important point in an alleged prophecy is to show that it was written before its fulfilment. But here this is undisputed, since everyone admits that the whole of the Old Testament, except some of the apocryphal books, was written before the time of Christ. And as the writings have been preserved by the Jews themselves, who are opposed to the claims of Christianity, we may be sure that not a single alteration in its favour has been made anywhere. We will now examine a few of the strongest prophecies, avoiding all those that were only fulfilled in a figurative, or spiritual sense; and selecting whole passages rather than single texts. For though many of these latter are very applicable to Christ, they might also be applicable to someone else. So we will first discuss somewhat fully Isaiah's prophecy of the Lord's Servant, and the Psalm of the Crucifixion; and then examine more briefly a group of prophecies referring to the Divinity of the Messiah. (A.) Isaiah's Prophecy of the Lord's Servant (52. 13-53. 12). It may be pointed out at starting that no one denies the antiquity of the passage, even if it was not written by Isaiah. And it forms a complete whole, closely connected together and not mixed up with any other subject. So in regard to its fulfilment, most of the details mentioned occurred within a few hours. We will consider first the historical, and then the doctrinal agreement. (1.) The Historical Agreement.
  • 63.
    With regard tothis, the following is the translation from the Revised Version, together with the corresponding events. It will be observed that the sufferings of the Servant are usually expressed in the past tense, and his triumph in the future, the prophet placing himself, as it were, between the two. But the Hebrew tenses are rather uncertain, and what is translated as past in the Revised Version is translated as future in the Authorised (e.g., 53. 2). 52. 13. 'Behold, my servant shall deal wisely, he shall be exalted and lifted up, and shall be very high. The excellence of Christ's teaching and conduct is now generally admitted; while as to His exalted position, He is worshipped by millions of men. 14. 'Like as many were astonied at thee (his visage was so marred more than any man, and his form more than the sons of men) so shall he sprinkle many nations; Yet at the time of His death, which was public so that many saw Him, the cruel treatment He had received must have terribly disfigured His face and body. 15. 'Kings shall shut their mouths at him: for that which had not been told them shall they see; and that which they had not heard shall they understand. But now even Kings are silent with reverence,[366] when contemplating such a wonderful life. 53. 1. 'Who hath believed our report? Indeed what the prophet is about to declare, is so marvellous that it can scarcely be believed. 'and to whom hath the arm of the Lord been revealed? The Arm of the Lord evidently means some instrument, or Person, which God uses for His work, as a man might use his arm.[367] And here it must be a Person, from the following words, 'For he grew up,' etc. It is thus a most suitable term for the Messiah, who was to be recognised by hardly anyone. 2. 'For he grew up before him as a tender plant, and as a root out of a dry ground: This was because He lived at a place (Nazareth) which was always regarded as dry ground so far as anything good was concerned.[368] he hath no form nor comeliness; and when we see him, there is no beauty that we should desire him. Moreover, His appearance was humble, and when at His trial, Pilate presented Him to the people, they did not desire Him. 3. 'He was despised, and rejected of men; a man of sorrows, and acquainted with grief: and as one from whom men hide But they at once rejected Him as they had done often before.
  • 64.
    their face hewas despised, and we esteemed him not. 4. 'Surely he hath borne our griefs, and carried our sorrows: yet we did esteem him stricken, smitten of God, and afflicted. While His life was not only one of grief and sorrow, but such a death seemed to show that He was accursed of God, for the Jews so regarded anyone who was crucified.[369] 5. 'But he was wounded for our transgressions, he was bruised for our iniquities: the chastisement of our peace was upon him; and with his stripes we are healed. The scourging and other ill-treatment is here referred to; including probably the nails, and spear, for the word translated wounded is literally pierced. 6. 'All we like sheep have gone astray; we have turned every one to his own way; and the Lord hath laid on him the iniquity of us all. 7. 'He was oppressed, yet he humbled himself and opened not his mouth; as a lamb that is led to the slaughter, and as a sheep that before her shearers is dumb; yea, he opened not his mouth. Christ, who is sometimes called the Lamb of God, not only bore His ill-treatment patiently, but refused to plead at either of His trials (the verse repeats twice He opened not His mouth) to the utter astonishment of His judges.[370] 8. 'By oppression and judgment he was taken away; and as for his generation, who among them considered that he was cut off out of the land of the living? for the transgression of my people was he stricken. He was not killed accidentally, or by the mob, but had a judicial trial; and was most unjustly condemned. While few, if any, of His contemporaries understood the real meaning of His death. 9. 'And they made his grave with the wicked, and with the rich in his death (i.e., when he was dead. Comp. Ps. 6. 8); He was appointed to die between two robbers, and would doubtless have been buried with them, had not Joseph of Arimathea intervened; when, in strange contrast with His ignominious death, He was honourably buried, with costly spices, and in a rich man's tomb. although he had done no violence, neither was any deceit in his mouth. Although His judge repeatedly declared that He was innocent. 10. 'Yet it pleased the Lord to bruise him; he hath put him to grief: when thou shalt make his soul an offering for sin, he shall see his seed, he shall prolong his days, and the pleasure of the Lord shall prosper in his hand. Yet after His death He was to see His seed, and prolong His days, i.e., rise again from the dead. The word seed cannot mean here, actual children,[371] since He was to obtain them by His death. But it may well refer to the disciples, whom Christ saw after His Resurrection, and called His children.[372]
  • 65.
    11. 'He shallsee of the travail of his soul, and shall be satisfied: by his knowledge shall my righteous servant justify many: and he shall bear their iniquities. And this is confirmed by their being spoken of as the travail of His soul, not body. While the latter expression also implies that He had had some intense mental struggle comparable to the bodily pains of childbirth; which is very suitable to His mental agony in the Garden and on the Cross. 12. 'Therefore will I divide him a portion with the great, and he shall divide the spoil with the strong; His subsequent triumph in the Christian Church is here alluded to. because he poured out his soul unto death, This implies that His sufferings were of some duration; and is thus very appropriate to a lingering death like crucifixion. and was numbered with the transgressors: yet he bare the sin of many, and made intercession for the transgressors.' While the closing words exactly agree with His dying a shameful death between two robbers; yet praying for His murderers, 'Father, forgive them.' [366] Comp. Job 29. 9. [367] Comp. Isa. 40. 10; 51. 9. [368] John 1. 46. [369] Deut. 21. 23; Gal. 3. 13. [370] Matt. 26. 62; 27. 14. [371] Comp. Isa. 1. 4. [372] Mark 10. 24; John 21. 5. It seems hardly necessary to insist on the agreement shown above; it is indisputable. The sufferings and the triumph of the Lord's Servant are foretold with equal confidence and with equal clearness, though they might well have seemed incompatible. (2.) The Doctrinal Agreement. But the significance of the passage does not depend on these prophecies alone, though they are sufficiently remarkable, but on the meaning which the writer assigns to the great tragedy. It is the Christian doctrine concerning Christ's death, and not merely the events attending it, which is here insisted on. This will be best
  • 66.
    shown by adoptingthe previous method of parallel columns, showing in the first the six chief points in the Christian doctrine, and in the other the prophet's words corresponding to them. All mankind are sinners. 'All we like sheep have gone astray.' Christ alone was sinless. 'My righteous servant.' 'He had done no violence, neither was any deceit in his mouth.' He suffered not for His own sins, but for those of others. Nor was this the mere accidental suffering of an innocent man for a guilty one; it was a great work of atonement, an offering for sin. This is the central feature of the Christian doctrine, and it is asserted over and over again in the prophecy, which is above all that of a Saviour. 'Surely he hath borne our griefs, and carried our sorrows.' 'He was wounded for our transgressions, he was bruised for our iniquities; the chastisement of (i.e., which procured) our peace was upon him; and with his stripes we are healed.' 'The Lord hath laid on him the iniquity of us all.' 'For the transgression of my people was he stricken.' 'Thou shalt make his soul an offering for sin.' 'He shall bear their iniquities.' 'He bare the sin of many.' And this Atonement was the fulfilment of the old Jewish sacrifices; especially that of the Paschal Lamb; so there was a special fitness in Christ's being put to death at the time of the Passover. This is shown by the language employed, the offering for sin being the same word as that used for the old guilt-offering.[373] And the curious expression So shall he sprinkle many nations evidently refers to the sprinkling of the blood in the Jewish sacrifices, as the same word is used, and means cleansing them from sin.[374] Yet it availed not only for the Jews, but for all mankind. The many nations must include Gentiles as well as Jews. Lastly, Christ's sacrifice was voluntary; He freely laid down His life, no one took it from Him (John 10. 18). 'He poured out his soul unto death,' implies that the act was voluntary, and this is rendered still clearer from the context; for it was because He did this that He was to divide the spoil, etc. And the words He humbled Himself, also imply that the humiliation was voluntary. [373] E.g., Lev. 7. 1. [374] E.g., Lev. 16. 19. All this, it is plain, exactly suits the Christ in whom Christians believe; and it does not and cannot suit anyone else, since several of the Christian doctrines are quite unique, and do not occur in the Jewish
  • 67.
    or any otherreligion. This is indeed so striking, that if anyone acquainted with Christianity, but unacquainted with Isaiah, came across the passage for the first time, he would probably refer it to one of St. Paul's Epistles. And every word of it might be found there with perfect fitness. (3.) The modern Jewish interpretation. Now, what can be said on the other side? Many of the ancient Jews interpreted the passage as referring to their future Messiah;[375] but the modern Jews (and most critics who disbelieve in prophecy) refer it to the Jewish nation, or to the religious part of it, which they say is here personified as a single man, the Servant of the Lord. And it must of course be admitted that Isaiah does frequently speak of the Jews as God's servant (e.g., 'But thou Israel, my servant, and Jacob whom I have chosen,')[376] though he nowhere else uses the term 'my righteous servant,' which he does here, and which would have been inapplicable to the nation. [375] References are given in Edersheim's 'Life and Times of Jesus the Messiah,' 1901, vol. ii., p. 727. [376] Isa. 41. 8. But it is important to remember that this prophecy does not stand alone, and a little before, we read in a similar passage, 'It is too light a thing that thou shouldest be my servant to raise up the tribes of Jacob, and to restore the preserved of Israel: I will also give thee for a light to the Gentiles, that thou mayest be my salvation unto the end of the earth. Thus saith the Lord, the Redeemer of Israel, and his Holy One, to him whom man despiseth, to him whom the nation abhorreth, to a servant of rulers: Kings shall see and arise; princes, and they shall worship.'[377] [377] Isa. 49. 6-7; comp. 42. 1-6. Here it will be noticed the Lord's servant is clearly distinguished from both Jacob and Israel, and evidently means the Messiah. While His bringing salvation to the Gentiles, as well as to the Jews; His
  • 68.
    humiliation in beingdespised by men and hated by the Jewish nation; and His subsequent triumph, even Kings submitting themselves to Him; are all alluded to, much as they are in the present passage. No doubt there is a difficulty in the prophet thus passing from one meaning of the word servant to another (especially, in a closely connected passage),[378] and various attempts have been made to explain it; but it does not alter the fact that he does so. Perhaps the best explanation is that Israel was intended to be God's Servant, but owing to their sins became unfitted; when God promised in the future to raise up a righteous servant, who should do all His pleasure and atone for Israel's failure. And, it may be added, the term Servant is applied to the Messiah both by Ezekiel and Zechariah, as well as in the New Testament.[379] [378] Isa. 49. 3, 5. [379] Ezek. 34. 23; Zech. 3. 8; Acts 3. 13 (R.V.). Moreover, the Jewish interpretation not only leaves all the details of the prophecy unexplained and inexplicable, but ignores its very essence, which, as before said, is the atoning character of the sufferings. No one can say that the sufferings of the Jews were voluntary, or that they were not for their own sins, but for those of other people, which were in consequence atoned for. Or, to put the argument in other words, if the He refers to the Jewish nation, to whom does the our refer in such sentences as He was wounded for our transgressions? While v. 8 expressly says that the Jews (God's people) were not the sufferers, but those for whom He suffered. (For the transgression of my people was he stricken.) This interpretation then is hopelessly untenable, and the passage either means what Christians assert, or it means nothing. In conclusion, it must be again pointed out that all these minute historical details attending Christ's death, and all these remarkable Christian doctrines concerning it, are all found within fifteen verses of a writing many centuries older than the time of Christ. It would be
  • 69.
    hard to over-estimatethe great improbability of all this being due to chance; indeed, such a conclusion seems incredible. (B.) The Psalm of the Crucifixion (Ps. 22).[380] [380] This is discussed more fully in an article in the Churchman, April, 1912, by the present writer. We pass on now to another most remarkable prophecy; for this well- known Psalm describes what can only be regarded as a crucifixion. The decisive verse is of course, They pierced my hands and my feet; but even apart from this, the various sufferings described cannot all be endured in any other form of death, such as stoning or beheading. And the Psalm agrees with the Death of Christ, both in its numerous details, and in its whole scope and meaning. We will therefore consider this close agreement first, and then some of the objections. (1.) Its close agreement. We need not quote the Psalm, as it is so well known; but will point out the agreement verse by verse. Ver. 1. His feeling forsaken by God, and using these actual words: 'My God, my God, why hast thou forsaken me?' 2. as well as praying for deliverance during the previous night; 3. though in spite of His sufferings, He casts no reproach upon God. 4. His belonging to God's chosen people, the Jews, so that He could speak of our fathers; 5. who had so often been helped by God before. 6. His pitiable condition in being exposed to the scorn and reproach of men, and despised by
  • 70.
    the people. 7. Hisbeing lifted up to die in public, so that those who passed by could see Him; and the way in which they mocked Him, shaking their heads, etc. 8. The exact words they used: He trusted on the Lord that He would deliver him, let Him deliver him seeing He delighteth in him (margin). These words show that the speakers themselves were Jews, and that He was thus put to death among His own nation. And the last clause can only be meant ironically in the sense that the Sufferer claimed that God delighted in him, claimed, that is, in some special sense to be beloved by God. 9. And, as a matter of fact, God had always watched over Him, and had saved Him in His infancy from being slain by Herod. 10. And in return His whole life had been dedicated to God; so that He could say that God had been His God, even from His birth. 11. His being abandoned by His disciples, and left without a helper; 12. though surrounded by His enemies, described as bulls of Bashan. This curious term is used elsewhere for the unjust rulers of the people, [381] and was therefore very applicable to the chief priests and rulers, who had so unjustly condemned Him, and now stood round the Cross reviling Him.
  • 71.
    [381] Amos. 4.1. 13. And they continually insulted Him, gaping with the mouth being a common expression of contempt;[382] ravening appropriate to the way in which they had thirsted for His blood before Pilate; and roaring to the great noise and tumult made at the time. [382] E.g., Job 16. 10. 14. His side being pierced, so that there poured out a quantity of watery fluid (mixed with clots of blood), the probable cause of this— the rupture of the heart[383] —being also hinted at; while His bones were nearly out of joint, through the weight of the suspended Body. [383] See 'The Physical Cause of the Death of Christ,' by Dr. Symes Thompson, 1904. 15. His suffering extreme weakness, and extreme thirst, immediately before His death.[384] [384] Lam. 4. 4; John 19. 28-30. 16. His being crucified (i.e., His hands and feet being pierced), the men who did this being here called dogs. They seem to have been a special set of men, different from the Jews who had before been mocking Him. And as this was the very term used by Christ Himself for the Gentiles, in distinction to the Jews,[385] it was peculiarly appropriate to the Gentile (Roman) soldiers who crucified Him. [385] Matt. 15. 26.
  • 72.
    17. And theyalso exposed and stretched out His Body, so that the bones stood out in relief. And they then stood watching Him; 18. and divided His garments among them, casting lots for one of them. 19. Then follows a short prayer. 20. The term sword, like the dog, the lion's mouth, and the wild oxen, need not be pressed literally; but may be used here (as in other places)[386] for any violent death. And in the New Testament it seems employed for all punishments, including probably a death by crucifixion (St. Peter's).[387] [386] Comp. 2 Sam. 11. 24; 12. 9. [387] Rom. 13. 4; Matt. 26. 52. 21. Yet in spite of His troubles, and even death, He feels sure of deliverance. 22. And now the strain suddenly changes, the Sufferer is restored to life and freedom and at once declares God's name unto His brethren. And this exactly agrees with Christ's now declaring for the first time God's complete Name of, Father, Son, and Holy Ghost, unto His brethren, as He calls them, the Apostles. [388] While if we identify this appearance with that to the five hundred, it was literally in the midst of the congregation—in the presence, that is, of the first large Christian assembly. [388] Matt. 28. 10, 19.
  • 73.
    23. Moreover, Hisdeliverance is of world-wide significance, and great blessings are to follow from it. These commence with the Jews, who were to praise and glorify God; though with a strange feeling of awe and fear; all of which was exactly fulfilled.[389] [389] Acts 2. 43-47. 24. And the blessings are somehow connected with God's not having despised, but having accepted, His sufferings. 25. And they include a reference to some vows (meaning uncertain); 26. and to a wonderful feast generally thought to refer to the Holy Communion. 27. And the blessings then extend to the Gentile nations also, even to the most distant parts of the world, who are now to become worshippers of the true God, Jehovah. And, as a matter of fact, Christians exist in all known countries, and wherever there are Christians, Jehovah is worshipped. 28. To Whom the whole earth, both the Jewish kingdom and the Gentile nations, really belongs. 29. And to Whom everyone will eventually bow down. 30. After this we read of a seed serving Him, probably used here, as in Isaiah, for disciples, each generation of whom is to tell of this wonderful deliverance to the next. And this they have been doing for eighteen centuries.
  • 74.
    31. And sothey will continue doing to generations that are yet unborn. While the closing words, He hath done it (R.V.) are often taken as referring to the whole Psalm, meaning that the work of suffering and atonement was now complete, It is done;[390] and they would thus correspond to Christ's closing words on the Cross, It it finished. [390] Hengstenberg, Commentary on Psalms, 1867, vol. i., 396. Everyone must admit that the agreement all through is very remarkable; though there are two slight objections. (2.) Two objections. The first is that there is nothing to show that the writer meant the Psalm to refer to the Messiah at all, though, strange to say, some of the Jews so interpreted it;[391] therefore if there is an agreement, it is at most only a chance coincidence. But the idea of all these coincidences being due to chance is most improbable. And there certainly is some indication that it refers to the Messiah, since, as we have seen, it leads up to the conversion of the Gentiles, which the other Jewish prophets always associate with the times of the Messiah. [391] Edersheim, 1901, vol. ii., 713. Moreover, if the Psalm does not refer to Christ, it is difficult to see to whom it does refer, since it is quite inapplicable to David, or Hezekiah, or anyone else at that time; as crucifixion was not a Jewish punishment, though dead bodies were sometimes hung on trees. Yet, as just said, verses 7-8 show that the Sufferer was put to death among his own nation. This strange anomaly of a Jew being put to death among Jews, though not in the Jewish manner by stoning, but by crucifixion, exactly suits the time of Christ, when Judæa was a Roman province, and crucifixion a Roman punishment.
  • 75.
    Many of thedetails also are quite inapplicable. David, for instance, never had his garments divided among his enemies; yet (even apart from our Gospels) there can be little doubt that the garments of Christ were so divided, as the clothes of a prisoner were usually taken by the guard who executed him. And any such reference (to David, etc.) is rendered still more improbable, because the sufferer appears to have no sense of sin, and never laments his own wickedness, as the writers so frequently do when speaking about themselves. And here also the Psalm is entirely applicable to Christ, since (as we shall see in the next chapter) His sinlessness was a striking feature in His character. Nor again did the deliverance of David in any way lead to the conversion of the Gentiles, which, as just said, is the grand climax of the Psalm, and excludes all other interpretations. But in any case this objection (which is also made to other Old Testament prophecies) cannot be maintained; for who, we must ask, was their real author? Was it the human prophet, or was it God Who inspired the prophet to write as he did? And the prophets themselves emphatically declared that it was the latter. The word of the Lord came unto them, or a vision was granted unto them, and they had to proclaim it, whether they liked it or not. In fact, as St. Matthew says, it was not really the prophet who spoke, but God, who spoke through the prophet.[392] There is thus no reason for thinking that they either knew, or thought they knew, the whole meaning of their prophecies; and the objection may be dismissed at once. [392] E.g., Matt. 1. 22. The second objection is, that some of the events fulfilling this, and other Old Testament prophecies, never occurred, but were purposely invented. This, however, destroys altogether the moral character of the Evangelists, who are supposed to tell deliberate falsehoods, in order to get a pretended fulfilment of an old prophecy. And the difficulty of admitting this is very great. Moreover, such explanations
  • 76.
    can only applyto a very few cases; since, as a rule, the events occurred in public, and must therefore have been well known at the time. And even in those cases where the event was so trivial, that it might possibly have been invented, such an explanation is often untenable. Take, for example, the manner in which Christ on the cross was mocked by His enemies, who said, 'He trusted in God, let him deliver him now if he desireth him.'[393] A more probable incident under the circumstances can scarcely be imagined, the chief priests quoting the familiar language (just as men sometimes quote the Bible now) without thinking of its real significance. But, supposing the words were never uttered, is it conceivable that the Evangelist (or anyone else) would have invented them in order to get a pretended fulfilment of this Psalm, where the Crucified One is mocked with almost identical words; yet have never pointed out the fulfilment himself, but have trusted to the chance of his readers discovering it? [393] Matt. 27. 43. Neither of these objections, then, is of much importance; while the agreement of the Psalm with the events attending the death and Resurrection of Christ, seems, as in the previous case, to be far too exact to be accidental. (C.) The Divinity of the Messiah. Our last example shall be of a different kind from the others. It is that the Old Testament contains several passages which show that the future Messiah was to be not only Superhuman, but Divine. And considering the strong Monotheism of the Jews this is very remarkable. The following are three of the most important:— 'For unto us a child is born, unto us a son is given; and the government shall be upon his shoulder: and his name shall be called Wonderful, Counsellor, Mighty God, Everlasting Father, Prince of Peace.'[394] Here we have a plain statement of the Divinity of One Who should be born a child. The two words translated Mighty God
  • 77.
    are incapable ofany other translation, and no other is suggested for them in the margin of either the Authorised or Revised Version; while the same two words occur in the next chapter, where they plainly mean Mighty God and nothing else. Moreover, the term Everlasting Father is literally Father of Eternity (see margin) and means the Eternal One. This is another divine title, and does not conflict with the Christian doctrine that it was the Son, and not the Father, Who became Incarnate. While the following words, that of the increase of His government there shall be no end, and that it should be established for ever, also point to a Divine Ruler, in spite of the reference to David's throne. And it is significant that a few verses before it is implied that the Ministry of this future Messiah should commence in the land of Zebulon, and Naphtali, by the Sea of Galilee; where, as a matter of fact, Christ's Ministry did commence. [394] Isa. 9. 6; 10. 21; 9. 1-2. 'But thou, Bethlehem Ephrathah, which art little to be among the thousands of Judah, out of thee shall one come forth unto me that is to be ruler in Israel; whose goings forth are from of old, from everlasting.'[395] Here we have a prophecy of the birth of One who had existed from everlasting; thus showing the Pre-existence and apparent Divinity of the Messiah, who was to be born at Bethlehem, where, again, as a matter of fact, Christ actually was born. [395] Mic. 5. 2. 'Awake, O sword, against my shepherd, and against the man that is my fellow, saith the Lord of hosts.'[396] The word translated fellow is only found elsewhere in Leviticus, where it is usually translated neighbour, and always implies an equality between the two persons. [397] Thus God speaks of the Shepherd who was to be slain with the sword (a term, as before said, used for any violent death), as equal with Himself, and yet at the same time Man; so no one but a Messiah who is both God and Man—Fellow-God as well as fellow- man—can satisfy the language.
  • 78.
    [396] Zech. 13.7. [397] Lev. 6. 2; 18. 20; 19. 11, 15, 17; 24. 19; 25. 14, 15, 17. And here again the reference to Christ is confirmed by the fact that several incidents in His Passion are alluded to, in some of which His Divinity is likewise asserted. The most important are the way in which He (the Just Saviour) rode into Jerusalem on an ass; and the rejoicing with which He was received, when the people welcomed Him as their King. And the fact that He (the Lord Jehovah) should be sold for thirty pieces of silver, the money being cast down in the House of the Lord, and afterwards given to the potter; and also that He (again the Lord Jehovah) should be pierced.[398] These are, it is true, expressed in figurative language, and often mixed up with other subjects; so no instance by itself, affords a strong argument. But still their all occurring so close together, and all leading up to the violent death of a man, who was yet the fellow, or equal, with God, can scarcely be accidental. While the prophecy, like so many others, ends with the conversion of the Gentiles, the Lord Jehovah being recognised as King over all the earth; which seems to place the Messianic character beyond dispute. [398] Zech. 9. 9; 11. 12-13; 12. 10; 14. 9; Luke 19. 37-38. The Divinity of the Messiah is also involved in some hints which occur in the Old Testament as to the doctrine of the Trinity. For instance, the Hebrew word for God, Elohim, is a plural word, though, strange to say, it generally takes a singular adjective, and verb. Thus if we tried to represent it in English, the first verse of the Bible would read, 'In the beginning the Gods, He created the heaven and the earth.' Attempts have of course been made to reduce the significance of this by pointing out that a few other Hebrew words, such as lord and master, sometimes do the same; or by regarding it as a survival from some previous polytheistic religion; or else as being what is called the plural of Majesty, a sort of royal We. This, however, does not seem to have been in use in early times, and never occurs in the Bible, where kings always speak of themselves in the singular.[399] Anyhow it is very remarkable that the Jews should
  • 79.
    Welcome to ourwebsite – the perfect destination for book lovers and knowledge seekers. We believe that every book holds a new world, offering opportunities for learning, discovery, and personal growth. That’s why we are dedicated to bringing you a diverse collection of books, ranging from classic literature and specialized publications to self-development guides and children's books. More than just a book-buying platform, we strive to be a bridge connecting you with timeless cultural and intellectual values. With an elegant, user-friendly interface and a smart search system, you can quickly find the books that best suit your interests. Additionally, our special promotions and home delivery services help you save time and fully enjoy the joy of reading. Join us on a journey of knowledge exploration, passion nurturing, and personal growth every day! ebookbell.com