java - Spring Property Injection with Play2 Framework -
I like many features of Play Framework 2 (I'm using it with Java), but the dependency injection fan As a matter of fact, I especially love the spring and in particular, injecting the configuration into objects using Therefore, I would love to know how the value of the property, using the built-in property resolution mechanism of a frequency variable play something like this: Anyone have any clues? Many thanks in advance. I had the same problem even a while back and this was the way to do this: First of all, when you promote your spring application context (I use annotation based configuration, but it should work for XML based), you have to add a custom , Which enables the way in which other than the new way to solve spring properties. Received some: Custom class To do all this work you only need to do one more thing: Clearly declare any kind of bean which you are using Be: It works like a charm for me, hope it is useful for someone else! Cheers, Jonathan @Value annotations.
@Component public class SpringBeanWithinAPlay2Application { @Value ("$ {application.timeout: 10}") Private int timeout; }
public static void start () {ctx = new Antateshn Config Aplifikeshn Kansteks (); Ctx.getEnvironment (). GetPropertySources (). AddFirst (new PlayFrameworkPropertySource ()); Ctx.scan ("somepackage"); Ctx.refresh (); }
PlayFrameworkPropertySource does such magic:
public class PlayFrameworkPropertySource PropertySource & lt; Object & gt; {Public PlayFrameworkPropertySource () {Super ("Resolution Mechanism of Play Framework Properties"); } @OverWide public object getProperty (string proprietary) {// or ConfigFactory.load (). GetString (propertyName), as you like ... Configuration Configuration.root (). GetString (propertyName); }}
@ Bean Public Static Property Source Placeholder Configurator Properties Placeholder Configurator () {New Property Site Placeholder Configurator (); } Important note: this bean should be
static , because it is one and it is before any other regular @ bean Should be loaded.
Comments
Post a Comment