This commit is contained in:
sxyx2008
2014-07-01 12:59:21 +08:00
parent c37bbd381c
commit 7901e0769a
77 changed files with 2020 additions and 0 deletions
@@ -0,0 +1,21 @@
package net.aimeizi.javaconfig.example;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class App {
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
HelloWorldService hello = (HelloWorldService) context.getBean("helloWorldBean");
hello.sayHello("Spring 3.2.3");
GoodbyeService bye = (GoodbyeService) context.getBean("goodbyeBean");
bye.sayGoodbye("Spring 3.2.3");
}
}
@@ -0,0 +1,10 @@
package net.aimeizi.javaconfig.example;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import(value={HelloConfig.class,GoodbyeConfig.class})
public class AppConfig {
}
@@ -0,0 +1,21 @@
package net.aimeizi.javaconfig.example;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AppXml {
@SuppressWarnings("resource")
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWorldService hello = (HelloWorldService) context.getBean("helloWorldBean");
hello.sayHello("Spring 3.2.3");
GoodbyeService bye = (GoodbyeService) context.getBean("goodbyeBean");
bye.sayGoodbye("Spring 3.2.3");
}
}
@@ -0,0 +1,14 @@
package net.aimeizi.javaconfig.example;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class GoodbyeConfig {
@Bean(name="goodbyeBean")
public GoodbyeService goodByeService() {
return new GoodbyeService();
}
}
@@ -0,0 +1,9 @@
package net.aimeizi.javaconfig.example;
public class GoodbyeService {
public void sayGoodbye(String name){
System.out.println("Goodbye from Java Configuration. "+ name);
}
}
@@ -0,0 +1,14 @@
package net.aimeizi.javaconfig.example;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class HelloConfig {
@Bean(name="helloWorldBean")
public HelloWorldService helloWorldService() {
return new HelloWorldService();
}
}
@@ -0,0 +1,9 @@
package net.aimeizi.javaconfig.example;
public class HelloWorldService {
public void sayHello(String name) {
System.out.println("Hello from Java Configuration. " + name);
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<import resource="classpath*:hello.xml" />
<import resource="classpath*:goodbye.xml" />
</beans>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<bean id="goodbyeBean"
class="net.aimeizi.javaconfig.example.GoodbyeService">
</bean>
</beans>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<bean id="helloWorldBean"
class="net.aimeizi.javaconfig.example.HelloWorldService">
</bean>
</beans>