When is spring 3.1 release




















Thanks for visiting DZone today,. Edit Profile. Sign Out View Profile. Over 2 million developers have joined DZone. Spring 3. Like 0. Join the DZone community and get the full member experience. This example shows how the configuration can be modularized into multiple classes, without sacrificing the ability to see at a glance where beans are defined. It is immediately obvious that the source and destination beans are configured in the BeanConfig class and that configuration is a ctrl-click away.

The Import BeanConfig. The listing below shows an example of loading the Spring container by supplying just the ServiceConfig class as a parameter. AnnotationConfigApplicationContext is an implementation of the Spring container that specifically works with Java or annotation-based configuration.

The above listing is an example of loading the container by passing configuration classes to the container's constructor. It is not necessary to pass the BeanConfig class, because it was imported into ServiceConfig. In a large application, it may be simpler to scan one or more packages to automatically find configuration classes instead of listing them explicitly when constructing the Spring container.

The above listing shows the use of the container's scan and refresh methods to load all configuration classes in the com. The Servlet 3.

Spring 3. SpringServletContainerInitializer searches the classpath of the Web application looking for any implementations of the Spring interface WebApplicationInitializer. Instead of being configured in a Web. The listing above shows an implementation that creates a Spring container using the scan method to find configuration classes. This Spring container must be passed to the constructor of a ContextLoaderListener , which must then be added as a listener to the servlet container.

The ContextLoaderListener will finish the initialization of the Spring container, calling refresh as necessary, and tie its lifecycle to that of the servlet container. Environment is a new abstraction that allows specific configurations to be loaded in different deployment environments, without modifying Spring configuration files or code.

The Environment has a set of active profiles that determine which bean configurations load. Each XML element, annotated application class, or configuration class can be assigned to zero or more profiles.

If none of their assigned profiles are active, they are ignored by Spring. If they are not assigned any profiles, they are always loaded. Because the Profile annotation can only be applied to classes, it is often convenient to nest inner configuration classes inside of outer ones. The ability to nest configuration classes is a new feature in Spring 3. In the listing above, the DataConfig class, which will eventually contain the Hibernate configuration, has two nested configuration classes- DataConfigDev and DataConfigProd.

They both contain a dataSource method that supplies a DataSource bean. Because each class has a different Profile annotation, the correct DataSource for the current environment will be instantiated and automatically injected into a field in the DataConfig class. A later example will show how the datasource field will be used to construct a Hibernate SessionFactory.

The active profiles can be set programmatically by calling setActiveProfiles on the Environment. In a Web application using a traditional web. The Profile annotation can be used to meta-annotate custom annotations. In the example above, a new Dev annotation is created, which can be used to annotate bean configurations instead of using Profile "dev".

Creating custom profile annotations avoids problems with typos or inconsistencies in profile names across multiple configuration classes. Configuring a Hibernate SessionFactory is a common task in Spring applications. Several of the Spring XML namespaces provide simple tags that turn on different functions of the framework. One example is the EnableTransactionManagement annotation shown in the listing above.

It is equivalent to the tag from the transaction namespace. Both the tag and the annotation activate processing of transaction-related annotations on application classes.

The listing above shows another configuration class, ServiceConfig , which imports the DataConfig class and uses the mediaDAO bean it provides to construct a mediaService bean. The mediaService bean will be used in the unit test example below. The ContextConfiguration annotation allows a test to run with a Spring container loaded from configuration classes.

ActiveProfiles is a new annotation that activates a set of profiles for a test run. In the listing above, the active profile is being set to "dev," and the ServiceConfig class is being loaded into a Spring container. This allows the test to use a MediaService bean to interact with the embedded test database created in the DataConfigDev class.

The previous sections have barely scratched the surface of the new features available in Spring 3. For a more complete list and additional resources, see the "New Features and Enhancements in Spring 3. Java-based configuration is an excellent choice going forward for both old and new Spring applications. It retains all the benefits of XML-based configuration while overcoming many of its shortcomings. It also presents an easier learning curve for Java developers new to Spring.

New Spring 3. Java 8 Project Lambda. Comparison of Angular 2 and React. Introduction To Grails. Search Site Map. Autowired ;. Component ;. Bean ;. Configuration ;. Scope ;. Thank you for participating in the discussion. Great summary of the latest additions to Spring 3. Simple but effective. If you're a Spring 3. They aren't necessary but makes developing Spring apps way easier. Hi, I'm passion about spring framework, but recently I having read a bit about Seam I found the programming model very attractive, I don't think we can get the same thing with webflow, the seamless integration of workflow engine in the application, can we?

Thank you Oscar. Like Print Bookmarks. Oct 29, 7 min read by Bienvenido David. Environment Abstraction and Bean Profiles Spring 3. Comprehensive Configuration Java-based application configuration has been enhanced and now has equivalent annotations to XML namespace functionality.

Configuration org. ComponentScan org. EnableLoadTimeWeaving org. EnableAspectJAutoProxy org. EnableScheduling org. EnableAsync org. EnableTransactionManagement org. EnableWebMvc The TestContext framework has been overhauled with first-class support for Configuration classes and environment profiles. Hibernate 4. Servlet 3. Additional Features Spring 3. Author Contacted. This content is in the Java topic.

Related Editorial. GraalVM Java News Roundup: Hibernate Reactive 1. Java News Roundup: Grails 5. What Does the Future Hold for Java? Why and How to Upgrade to Java 16 or What's New in Java Hibernate Releases Version 1. Implementing Pipeline Microservicilities with Tekton. Implementing Microservicilites with Istio. HashiCorp Vault 1. Overriding Sealed Methods in C. View an example Enter your e-mail address.



0コメント

  • 1000 / 1000