Yegor Bondar
1. Increase version of Spring dependencies
If you already have Spring 3.1.x/3.2.x then just change version to 4.x AND make sure that you added spring-context dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.0</version>
</dependency>
<import resource="classpath:/context/gbeans.groovy">
@Configuration
@PropertySources({
@PropertySource(value = "config.properties"),
@PropertySource(value = "config_repeat.properties", ignoreResourceNotFound = true)
})
@ImportResource(value = "classpath:/context/gbeans.groovy")
public class ApplicationConfiguration {...}
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/context/gbeans.groovy</param-value>
</context-param>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="gdbean" class="edu.spring.talk.gbeans.GDBean">
<property name="name" value="testname"/>
<property name="desc" value="testdesc"/>
</bean>
</beans>
package edu.spring.talk.gbeans import edu.spring.talk.gbeans.inner.IGADrivenBean beans { gdbean GDrivenBean, name:'testname', desc:'testdesc' gdbeanprops(GDrivenBean){
name = 'propname' desc = '${test.desc}' //properties file driven } igadbean(IGADrivenBean) {bean -> bean.scope = 'prototype' reference = ref 'gdbeanprops' s_reference = gdbean } }
import org.springframework.core.io.ClassPathResource def defaultScope = 'prototype' def properties = new Properties() properties.load(new ClassPathResource('application.properties').inputStream); beans { xmlns([ctx:'http://www.springframework.org/schema/context']) ctx.'component-scan'('base-package':properties.basePackage)
igadbean(IGADrivenBean) {bean -> bean.scope = defaultScope } }
beans {
if (environment.activeProfiles.contains("dev")) {
gdbean GDrivenBean, name:'testname', desc:'testdesc'
} else {
gdbean GDrivenBean, name:'prodname', desc:'proddesc'
}
}
protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) {
callable.setDelegate(this);
callable.call();
finalizeDeferredProperties();
return this;
}
JdbcTemplate jt = new JdbcTemplate(dataSource);
jt.query("SELECT name, age FROM person WHERE dep = ?",
ps -> {
ps.setString(1, "Sales");
},
(rs, rowNum) -> {
return new Person(rs.getString(1), rs.getInt(2));
});
@PropertySources({ @PropertySource(value = "config.properties"), @PropertySource(value = "config_repeat.properties", ignoreResourceNotFound = true) })
public class Configuration {...}
@PropertySource("config.properties") @PropertySource("config_repeat.properties",
ignoreResourceNotFound = true)
public class Configuration {...}
@RequestMapping(value = "/bean/{name}", method = RequestMethod.GET)
public GDrivenBean getBean(@PathVariable Optional<String> name, @RequestParam Optional<String> desc){
bean.setName(name.orElseGet(() -> bean.getName()););
bean.setDesc(desc.orElse("default"));
return bean;
}
@Bean
JDrivenBean jDrivenBean(@Qualifier("gdbean")Optional<GDrivenBean> gdbean){
return new JDrivenBean("t");
}
public class JDrivenBean<T> { T value; }
@Component("jstringbean") public class JADrivenBean extends JDrivenBean<String> {...} @Component("jlongbean") public class JLongBean extends JDrivenBean<Long>{...}
<alias name="jbean" alias="jlongbean">
@Autowired
@Qualifier("jbean")
private JLongBean bean;
@Autowired private JDrivenBean<String> genericBean;
With the exception of value(), meta-annotated types may redeclare attributes from the source annotation to allow user customization.
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping("/webservice")
@RestController
@Scope("request")
@Transactional(isolation = Isolation.DEFAULT)
public @interface WebServiceController {
Propagation propagation() default Propagation.REQUIRES_NEW;
String [] headers() default {};
}
@WebServiceController
public class BeanRestController {...}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {...}
@RestController
public class BeanController{
@RequestMapping(value = "/get/bean", method = RequestMethod.GET)
public TestBean get(){...}
}
yieldUnescaped '<!DOCTYPE html>' html(lang:'en') { head { meta('http-equiv':'"Content-Type" content="text/html; charset=utf-8"')
title('My page') } body { p('This is an example of HTML contents') } }