File tree Expand file tree Collapse file tree
springtest/test1/HelloSpring
java/com/jsoft/test/hellospring
test/java/com/jsoft/test/hellospring Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <classpath >
3+ <classpathentry kind =" src" output =" target/classes" path =" src/main/java" >
4+ <attributes >
5+ <attribute name =" optional" value =" true" />
6+ <attribute name =" maven.pomderived" value =" true" />
7+ </attributes >
8+ </classpathentry >
9+ <classpathentry kind =" src" output =" target/test-classes" path =" src/test/java" >
10+ <attributes >
11+ <attribute name =" optional" value =" true" />
12+ <attribute name =" maven.pomderived" value =" true" />
13+ </attributes >
14+ </classpathentry >
15+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8" >
16+ <attributes >
17+ <attribute name =" maven.pomderived" value =" true" />
18+ </attributes >
19+ </classpathentry >
20+ <classpathentry kind =" con" path =" org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" >
21+ <attributes >
22+ <attribute name =" maven.pomderived" value =" true" />
23+ </attributes >
24+ </classpathentry >
25+ <classpathentry kind =" output" path =" target/classes" />
26+ </classpath >
Original file line number Diff line number Diff line change 1+ /target /
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <projectDescription >
3+ <name >HelloSpring</name >
4+ <comment ></comment >
5+ <projects >
6+ </projects >
7+ <buildSpec >
8+ <buildCommand >
9+ <name >org.eclipse.jdt.core.javabuilder</name >
10+ <arguments >
11+ </arguments >
12+ </buildCommand >
13+ <buildCommand >
14+ <name >org.eclipse.m2e.core.maven2Builder</name >
15+ <arguments >
16+ </arguments >
17+ </buildCommand >
18+ </buildSpec >
19+ <natures >
20+ <nature >org.eclipse.jdt.core.javanature</nature >
21+ <nature >org.eclipse.m2e.core.maven2Nature</nature >
22+ </natures >
23+ </projectDescription >
Original file line number Diff line number Diff line change 1+ eclipse.preferences.version =1
2+ encoding//src/main/java =UTF-8
3+ encoding//src/test/java =UTF-8
4+ encoding/<project>=UTF-8
Original file line number Diff line number Diff line change 1+ eclipse.preferences.version =1
2+ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode =enabled
3+ org.eclipse.jdt.core.compiler.codegen.methodParameters =do not generate
4+ org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.8
5+ org.eclipse.jdt.core.compiler.codegen.unusedLocal =preserve
6+ org.eclipse.jdt.core.compiler.compliance =1.8
7+ org.eclipse.jdt.core.compiler.debug.lineNumber =generate
8+ org.eclipse.jdt.core.compiler.debug.localVariable =generate
9+ org.eclipse.jdt.core.compiler.debug.sourceFile =generate
10+ org.eclipse.jdt.core.compiler.problem.assertIdentifier =error
11+ org.eclipse.jdt.core.compiler.problem.enumIdentifier =error
12+ org.eclipse.jdt.core.compiler.problem.forbiddenReference =warning
13+ org.eclipse.jdt.core.compiler.source =1.8
Original file line number Diff line number Diff line change 1+ activeProfiles =
2+ eclipse.preferences.version =1
3+ resolveWorkspaceProjects =true
4+ version =1
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+
5+ <groupId >com.jsoft.test</groupId >
6+ <artifactId >HelloSpring</artifactId >
7+ <version >1.0-SNAPSHOT</version >
8+ <packaging >jar</packaging >
9+
10+ <name >HelloSpring</name >
11+ <url >http://maven.apache.org</url >
12+
13+ <properties >
14+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15+ </properties >
16+
17+ <dependencies >
18+ <dependency >
19+ <groupId >junit</groupId >
20+ <artifactId >junit</artifactId >
21+ <version >3.8.1</version >
22+ <scope >test</scope >
23+ </dependency >
24+
25+ <!-- Spring Core -->
26+ <!-- http://mvnrepository.com/artifact/org.springframework/spring-core -->
27+ <dependency >
28+ <groupId >org.springframework</groupId >
29+ <artifactId >spring-core</artifactId >
30+ <version >4.1.4.RELEASE</version >
31+ </dependency >
32+
33+ <!-- Spring Context -->
34+ <!-- http://mvnrepository.com/artifact/org.springframework/spring-context -->
35+ <dependency >
36+ <groupId >org.springframework</groupId >
37+ <artifactId >spring-context</artifactId >
38+ <version >4.1.4.RELEASE</version >
39+ </dependency >
40+
41+ </dependencies >
42+ </project >
Original file line number Diff line number Diff line change 1+ package com .jsoft .test .hellospring ;
2+
3+ import org .springframework .context .ApplicationContext ;
4+ import org .springframework .context .support .ClassPathXmlApplicationContext ;
5+
6+ import com .jsoft .test .hellospring .helloworld .HelloWorld ;
7+ import com .jsoft .test .hellospring .helloworld .HelloWorldService ;
8+
9+ /**
10+ * Hello world!
11+ *
12+ */
13+ public class App
14+ {
15+ public static void main ( String [] args )
16+ {
17+ //IoC获取beans的上下文
18+ ApplicationContext context = new ClassPathXmlApplicationContext ("beans.xml" );
19+ //通过上下文获取beans创建的Service,此时已经注入了是创建哪个的接口实现
20+ HelloWorldService helloWorldService = (HelloWorldService )context .getBean ("helloWorldService" );
21+ //Service调用统一接口方法获取注入的接口实现
22+ HelloWorld helloWorld = helloWorldService .getHelloWorld ();
23+ //输出接口实现的内容
24+ helloWorld .sayHello ();
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ package com .jsoft .test .hellospring .helloworld ;
2+
3+ public interface HelloWorld {
4+ public void sayHello ();
5+ }
Original file line number Diff line number Diff line change 1+ package com .jsoft .test .hellospring .helloworld ;
2+
3+ public class HelloWorldService {
4+ private HelloWorld helloWorld ;
5+
6+ public HelloWorldService (){
7+
8+ }
9+
10+ public void setHelloWorld (HelloWorld helloWorld ){
11+ this .helloWorld = helloWorld ;
12+ }
13+
14+ public HelloWorld getHelloWorld (){
15+ return this .helloWorld ;
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments