Skip to content

Instantly share code, notes, and snippets.

/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Configuration
class TxConfig {
@SpecMethod
public TxAnnotationDriven tx() {
return new TxAnnotationDriven(this.txManager());
}
@Bean
public TransactionalTestBean testBean() {
@Configuration
class TxConfig {
@Feature
public TxAnnotationDriven tx() {
return new TxAnnotationDriven(this.txManager()).proxyTargetClass(false);
}
@Bean
public TransactionalTestBean testBean() {
@Configuration
class TxConfig {
@Feature
public TxAnnotationDriven tx() {
return new TxAnnotationDriven(this.txManager()).proxyTargetClass(false);
}
@SpringConfigured
public Order configureOrder(Order order) {
@cbeams
cbeams / gist:909683
Created April 8, 2011 11:42
100% @Configuration-based application (no component-scanning)
@Configuration
@TxAnnotationDriven
@PropertySource("classpath:/com/company/app/db.properties")
public class UnifiedConfig {
@Inject Environment env;
// ---- configure data infrastructure ----
@cbeams
cbeams / gist:909691
Created April 8, 2011 11:50
@Configuration-based application with component-scanning
@Configuration
@ComponentScan("com.company.app")
@TxAnnotationDriven
@PropertySource("classpath:/com/company/app/db.properties")
public class UnifiedConfig {
@Inject Environment env;
// ---- configure data infrastructure ----
@Configuration@TxAnnotationDriven
public abstract class AppConfig {
@Inject Environment env;
// ---- configure data infrastructure ----
public abstract DataSource dataSource();
@cbeams
cbeams / AppConfig.java
Created April 8, 2011 12:16
Demonstrating the problem with @feature and beans @injected from XML
@Configuration
@TxAnnotationDriven
@ImportResource("classpath:/com/company/app/db-config.xml")
public class AppConfig {
@Inject Environment env;
@Inject DataSource dataSource; // from XML -> won't work; @Feature forces autowiring before BFPP!
@Configuration
@Import(MyFrameworkConfiguration.class)
public class UserConfig implements MyFrameworkInitializer {
@Bean
public FooCallback fooCallback() {
return new FooCallback() {
public void doWithFoo(Foo foo) {
foo.setAwesome(true);
}
@Configuration
@Import(MyFrameworkConfiguration.class)
public class UserConfig implements MyFrameworkInitializer {
protected void setMyFrameworkInitializer(MyFrameworkInitializer initializer) {
super.setMyFrameworkInitializer(this)
}
public void configureFoo(Foo foo) {
foo.setAwesome(true);