org.springframework.scripting.groovy.GroovyScriptFactory Java Examples
The following examples show how to use
org.springframework.scripting.groovy.GroovyScriptFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptFactoryPostProcessorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testPrototypeScriptedBean() throws Exception { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); scriptedBeanBuilder.setScope(BeanDefinition.SCOPE_PROTOTYPE); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); final String BEAN_WITH_DEPENDENCY_NAME = "needsMessenger"; ctx.registerBeanDefinition(BEAN_WITH_DEPENDENCY_NAME, scriptedBeanBuilder.getBeanDefinition()); ctx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true)); ctx.refresh(); Messenger messenger1 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME); Messenger messenger2 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME); assertNotSame(messenger1, messenger2); }
Example #2
Source File: ScriptFactoryPostProcessorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testPrototypeScriptedBean() throws Exception { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); scriptedBeanBuilder.setScope(BeanDefinition.SCOPE_PROTOTYPE); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); final String BEAN_WITH_DEPENDENCY_NAME = "needsMessenger"; ctx.registerBeanDefinition(BEAN_WITH_DEPENDENCY_NAME, scriptedBeanBuilder.getBeanDefinition()); ctx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true)); ctx.refresh(); Messenger messenger1 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME); Messenger messenger2 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME); assertNotSame(messenger1, messenger2); }
Example #3
Source File: ScriptFactoryPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testPrototypeScriptedBean() throws Exception { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); scriptedBeanBuilder.setScope(BeanDefinition.SCOPE_PROTOTYPE); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); final String BEAN_WITH_DEPENDENCY_NAME = "needsMessenger"; ctx.registerBeanDefinition(BEAN_WITH_DEPENDENCY_NAME, scriptedBeanBuilder.getBeanDefinition()); ctx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true)); ctx.refresh(); Messenger messenger1 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME); Messenger messenger2 = (Messenger) ctx.getBean(BEAN_WITH_DEPENDENCY_NAME); assertNotSame(messenger1, messenger2); }
Example #4
Source File: ScriptFactoryPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testReferencesAcrossAContainerHierarchy() throws Exception { GenericApplicationContext businessContext = new GenericApplicationContext(); businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); businessContext.refresh(); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); GenericApplicationContext presentationCtx = new GenericApplicationContext(businessContext); presentationCtx.registerBeanDefinition("needsMessenger", scriptedBeanBuilder.getBeanDefinition()); presentationCtx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true)); presentationCtx.refresh(); }
Example #5
Source File: ScriptFactoryPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
private static BeanDefinition createScriptedGroovyBean() { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); builder.addConstructorArgValue("inline:package org.springframework.scripting;\n" + "class GroovyMessenger implements Messenger {\n" + " private String message = \"Bingo\"\n" + " public String getMessage() {\n" + " return this.message\n" + " }\n" + " public void setMessage(String message) {\n" + " this.message = message\n" + " }\n" + "}"); builder.addPropertyValue("message", MESSAGE_TEXT); return builder.getBeanDefinition(); }
Example #6
Source File: ScriptFactoryPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testReferencesAcrossAContainerHierarchy() throws Exception { GenericApplicationContext businessContext = new GenericApplicationContext(); businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); businessContext.refresh(); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); GenericApplicationContext presentationCtx = new GenericApplicationContext(businessContext); presentationCtx.registerBeanDefinition("needsMessenger", scriptedBeanBuilder.getBeanDefinition()); presentationCtx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true)); presentationCtx.refresh(); }
Example #7
Source File: ScriptFactoryPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
private static BeanDefinition createScriptedGroovyBean() { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); builder.addConstructorArgValue("inline:package org.springframework.scripting;\n" + "class GroovyMessenger implements Messenger {\n" + " private String message = \"Bingo\"\n" + " public String getMessage() {\n" + " return this.message\n" + " }\n" + " public void setMessage(String message) {\n" + " this.message = message\n" + " }\n" + "}"); builder.addPropertyValue("message", MESSAGE_TEXT); return builder.getBeanDefinition(); }
Example #8
Source File: ScriptFactoryPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testReferencesAcrossAContainerHierarchy() throws Exception { GenericApplicationContext businessContext = new GenericApplicationContext(); businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); businessContext.refresh(); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); GenericApplicationContext presentationCtx = new GenericApplicationContext(businessContext); presentationCtx.registerBeanDefinition("needsMessenger", scriptedBeanBuilder.getBeanDefinition()); presentationCtx.registerBeanDefinition("scriptProcessor", createScriptFactoryPostProcessor(true)); presentationCtx.refresh(); }
Example #9
Source File: ScriptFactoryPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private static BeanDefinition createScriptedGroovyBean() { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); builder.addConstructorArgValue("inline:package org.springframework.scripting;\n" + "class GroovyMessenger implements Messenger {\n" + " private String message = \"Bingo\"\n" + " public String getMessage() {\n" + " return this.message\n" + " }\n" + " public void setMessage(String message) {\n" + " this.message = message\n" + " }\n" + "}"); builder.addPropertyValue("message", MESSAGE_TEXT); return builder.getBeanDefinition(); }