commit
This commit is contained in:
+21
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -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 {
|
||||
|
||||
}
|
||||
+21
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -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>
|
||||
Reference in New Issue
Block a user