File: context.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
value1
Hello, world
How are you doing today?
foo
File: Main.java
import java.util.List;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;
public class Main {
private static void printMap(Map z) {
for (Object o : z.entrySet()) {
Map.Entry e = (Map.Entry) o;
System.out.println(e.getKey() + " => " + e.getValue().getClass() + " " + e.getValue());
}
}
private static void printList(List y) {
for (Object o : y) {
System.out.println(o.getClass() + " " + o);
}
}
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**/context.xml");
List y = (List) context.getBean("Y");
printList(y);
Map z = (Map) context.getBean("Z");
printMap(z);
Map p = (Map) context.getBean("P");
printMap(p);
}
}
class MyTransactionManager extends AbstractPlatformTransactionManager {
@Override
protected Object doGetTransaction() throws TransactionException {
System.out.println("doGetTransaction");
return new Object();
}
@Override
protected void doBegin(Object object, TransactionDefinition transactionDefinition)
throws TransactionException {
System.out.println("doBegin");
}
@Override
protected void doCommit(DefaultTransactionStatus defaultTransactionStatus)
throws TransactionException {
System.out.println("doCommit");
}
@Override
protected void doRollback(DefaultTransactionStatus defaultTransactionStatus)
throws TransactionException {
System.out.println("doRollback");
}
}
class SimpleBean {
private String name;
private String value;
public SimpleBean() {
this.name = "My name";
this.value = "My value";
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
}
File: Main.properties
foo=bar
baz=foobar