Git Product home page Git Product logo

play--framework-spring-module's Introduction

Spring module

The spring support module help you to integrate Spring managed beans with a play application.

Enable the Spring module for the application

In the /conf/application.conf file, enable the Spring module by adding this line:

# The spring module
module.spring=${play.path}/modules/spring

Define an application-context.xml registry

In the conf/ directory of the application you can then create a application-context.xml file and define some beans.

For example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springsource.org/dtd/spring-beans-2.0.dtd">
<beans>

Retrieve beans from application code

You can obtain bean instances from the application code, using the play.modules.spring.Spring helper.

public Application extends Controller {
public static void index() { Test test = Spring.getBeanOfType(Test.class); … }

}

@javax.inject.Inject support

Not implemented yet.

Automatic Component Scanning

Spring 2.5 and later supports auto-wiring and component identification using annotations, obviating the need to define beans explicitly in XML.

To enable component scanning, add this line to the /conf/application.conf file:

play.spring.component-scan=true

Note that enabling this scans for @org.springframework.stereotype.Component, @org.springframework.stereotype.Repository, @org.springframework.stereotype.Service to identify Spring beans. Additionally, running the component scan enables support for annotation based configuration (i.e., @org.springframework.beans.factory.annotation.Autowired, etc).

Limited Scanning

You can limit the classes scanned to specific packages or canonical class names with this line in the /conf/application.conf file:

play.spring.component-scan.base-packages=controllers.beans,services

In this example, only classes whose canonical name start with either ‘controllers.beans’ or ‘services’ will be scanned and identified as beans.

Manual PropertyPlaceholderConfigurer configuration

By default, a org.springframework.beans.factory.config.PropertyPlaceholderConfigurer containing the properties of application.conf is added to the Spring context. In some cases, this may not be desirable as it can conflict with a PropertyPlaceholderConfigurer that you have defined in your application-context.xml. To disable the automatic PropertyPlaceholderConfigurer placement into the context, update application.conf with

play.spring.add-play-properties=false

and then add your own definition to application-context.xml.

If you want to have your own properties and those of your Play! application handled by a PropertyPlaceholderConfigurer, you can add all of them in application-context.xml:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>
            <value>classpath:application.conf</value>
        </list>
    </property>
</bean>

Namespaces

If you want the Spring configuration loader to be namespace aware, you need to explicitly state this in the configuration using

play.spring.namespace-aware=true

play--framework-spring-module's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.