Terms in this set (36)
What is Spring and what are the benefits of using it?
Spring is open source that can build web/MVC applications on top of J2EE. The
■ Inversion of Control
● The objects give their dependencies instead of creating or looking
for dependent objects
Inversion of Control
The objects give their dependencies instead of creating or looking for dependent objects
Take away the control of object instantiation from the class and hand it over to an outside object factory (bean)
De-couples the code so that you don't have to rewrite the source code.
Creates and wires objects and functions
What are the different modules in the Spring framework?
Core Containers (dependency injection features)
Java Bean is a normal Java class which has private properties with its public getter and setter method.
Java Beans are generally used as helper class.
Java Database connectivity-allows Java apps to communicate to DB
Java Message Service
The core idea behind a transaction is that it's a complex operation completed as an all-or-nothing set of simpler operations. If one of the simpler operations fails, then none of the operations should be applied.
The classic example is making a purchase, and indeed this is probably where the name "transaction" comes from. There are several steps:
Pull funds from buyer's account
Add funds to seller's account
Decrease product inventory
atomic, consistent, isolated and durable. An operation is a transaction if and only if it has these four characteristics, which I'll describe briefly:
This is the aforementioned all-or-nothing property. Even though a transaction comprises multiple operations, it is completed as a single logical unit of work. Either the whole thing succeeds or none of it does.
We want our "transactional resource" (which in most cases means our database) to be consistent with reality. So for example if I have 4,132 widgets in stock after I sell you five of them, then I want the database to say that I have 4,132 widgets in stock after I run a sell(you, 5, widget) transaction. The consistency property means that after a transaction completes, the database (or whatever transactional resource we're using) matches up with the real world.
In general we want to be able to run lots of transactions against the database at the same time, and we don't want to make a big mess out of things in the process. The isolation property means that when you run a transaction, it achieves its results without interference from other transactions. That doesn't mean that the transactions can't run concurrently—it just means that the transactions shouldn't corrupt each other in the process. In practice it's nontrivial to strike the right balance between concurrency and isolation; transactions however exhibit some level of isolation, and well-designed transactions exhibit the "right" amount of isolation.
This just means that after a transaction has ended, its results are made persistent. Probably they would have called this property "persistent" instead of "durable", but "ACIP" is not as cool as "ACID".
What is Spring configuration file?
It is an XML file that contains contains the classes info and describes how these
classes are configured and introduced to each other
What is dependency injection?
One example of inversion of control
○ This concept says that you do not create your objects but describe how theyshould be created
■ You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file
○ Dependencies (management) are resolved at Spring own time
■ Singleton of dependencies
What are the different types of IoC
When the container invokes a class constructor with a number of arguments, each representing a dependency on other classes
When the container calling setter methods on your beans after invoking a no-argument constructor or no argument static factory method
What are the benefits of IoC?
○ Minimizes the amount of code
○ Application easy to unit test
○ Loose coupling
What is Spring IoC container?
It creates the objects, wire them together, configure them, and manage their
complete lifecycle from creation till destruction
■ Uses Ioc to manage this
What are the types of IoC containers?
■ Basic support of DI (dependency injection)
■ A set of classes to make a bean
Spring Application Context
■ Adds more enterprise-specific functionality such as the ability to resolve
textual messages from a properties file and the ability to publish
application events to interested event listeners
■ Fundamental functionality of Spring Framework
What are the differences of Bean Factory and ApplicationContext?
■ Provides a means for resolving text messages
■ Provides a means for loading file resources
■ Publish events to beans that are registered as listeners
○ Bean Factory
■ Have to be handled in a programmatic fashion with bean factory instead
Can you inject null and empty string values in spring?
What is auto-wiring?
○ It is possible to automatically let spring resolve collaborators (other beans) from your bean by inspecting the contents of the BeanFactory
How do you turn on annotation wiring?
○ Annotation wiring is not turned on in the Spring container by default. So, before
we can use annotation-based wiring, we need to enable it in the configuration file
What does @Required mean?
Indicates that the affected bean property must be populated at configuration time
● Can be used on the setter method
What does @Autowired mean?
Control over where and how the autowiring should be accomplished
● Can be used on the setter method
How is event handling done in spring?
Event handling in the ApplicationContext is provided through the ApplicationEvent class and the ApplicationListener interface.
What are some of the standard Spring events?
Published when the ApplicationContext is either initialized or refreshed
Published when the ApplicationContext is started using start() method on ConfigurableApplicationContext interface
Published when the ApplicationContext is stopped using the stop() method on the ConfigurableApplicationContext
Web-specific event telling all beans that an HTTP request has been serviced
What are the types of transaction management in Spring?
You have managed the transaction with the help of programming
You have separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions
Where is the business logic in MVC?
In the model
Gatekeeper of the data
What is a DispatcherServlet?
MVC is designed around the DispatcherServlet that handles all the HTTP requests and responses
What is the WebApplicationContext
Extension of the ApplicationContext that has some extra features for web applications
Capable of resolving themes and that it knows which servlet it is associated with
What is the Controller in MVC?
Provide access to the application behavior that you typically define through a service interface.
They interpret user input and transform it into a model that is represented to the user by the view
What is the @RequestMapping annotation
Used to map a URL to either an entire class or a particular handler method