Skip to content

Commit 3db64b8

Browse files
committed
logback test
1 parent 31984d2 commit 3db64b8

File tree

10 files changed

+225
-0
lines changed

10 files changed

+225
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
<!-- Logback -->
42+
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
43+
<dependency>
44+
<groupId>ch.qos.logback</groupId>
45+
<artifactId>logback-classic</artifactId>
46+
<version>1.2.3</version>
47+
</dependency>
48+
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core -->
49+
<dependency>
50+
<groupId>ch.qos.logback</groupId>
51+
<artifactId>logback-core</artifactId>
52+
<version>1.2.3</version>
53+
</dependency>
54+
<!-- https://mvnrepository.com/artifact/org.logback-extensions/logback-ext-spring -->
55+
<dependency>
56+
<groupId>org.logback-extensions</groupId>
57+
<artifactId>logback-ext-spring</artifactId>
58+
<version>0.1.4</version>
59+
</dependency>
60+
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
61+
<dependency>
62+
<groupId>org.slf4j</groupId>
63+
<artifactId>slf4j-api</artifactId>
64+
<version>1.7.25</version>
65+
</dependency>
66+
<!-- https://mvnrepository.com/artifact/org.slf4j/jcl-over-slf4j -->
67+
<dependency>
68+
<groupId>org.slf4j</groupId>
69+
<artifactId>jcl-over-slf4j</artifactId>
70+
<version>1.7.25</version>
71+
</dependency>
72+
73+
74+
75+
76+
</dependencies>
77+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.jsoft.test.hellospring;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.context.support.ClassPathXmlApplicationContext;
7+
8+
import com.jsoft.test.hellospring.helloworld.HelloWorld;
9+
import com.jsoft.test.hellospring.helloworld.HelloWorldService;
10+
11+
/**
12+
* Hello world!
13+
*
14+
*/
15+
public class App
16+
{
17+
private static final Logger logger = LoggerFactory.getLogger(App.class);
18+
19+
public static void main( String[] args )
20+
{
21+
logger.info("test");
22+
//IoC获取beans的上下文
23+
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
24+
//通过上下文获取beans创建的Service,此时已经注入了是创建哪个的接口实现
25+
HelloWorldService helloWorldService = (HelloWorldService)context.getBean("helloWorldService");
26+
//Service调用统一接口方法获取注入的接口实现
27+
HelloWorld helloWorld = helloWorldService.getHelloWorld();
28+
//输出接口实现的内容
29+
helloWorld.sayHello();
30+
}
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.jsoft.test.hellospring.helloworld;
2+
3+
public interface HelloWorld {
4+
public void sayHello();
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.jsoft.test.hellospring.helloworld.impl;
2+
3+
import com.jsoft.test.hellospring.helloworld.HelloWorld;
4+
5+
public class SpringHelloWorld implements HelloWorld {
6+
7+
@Override
8+
public void sayHello() {
9+
// TODO Auto-generated method stub
10+
System.out.println("Spring say HelloWorld!");
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.jsoft.test.hellospring.helloworld.impl;
2+
3+
import com.jsoft.test.hellospring.helloworld.HelloWorld;
4+
5+
public class StrutsHelloWorld implements HelloWorld {
6+
7+
@Override
8+
public void sayHello() {
9+
// TODO Auto-generated method stub
10+
System.out.println("Struts say HelloWorld!");
11+
}
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<beans xmlns="http://www.springframework.org/schema/beans"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans
4+
http://www.springframework.org/schema/beans/spring-beans.xsd">
5+
6+
<bean id="springHelloWorld" class="com.jsoft.test.hellospring.helloworld.impl.SpringHelloWorld"></bean>
7+
<bean id="strutsHelloWorld" class="com.jsoft.test.hellospring.helloworld.impl.StrutsHelloWorld"></bean>
8+
9+
<bean id="helloWorldService" class="com.jsoft.test.hellospring.helloworld.HelloWorldService">
10+
<property name="HelloWorld" ref="strutsHelloWorld"/>
11+
</bean>
12+
13+
</beans>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<!-- 控制台输出 -->
4+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5+
<!-- 日志输出编码 -->
6+
<Encoding>UTF-8</Encoding>
7+
<layout class="ch.qos.logback.classic.PatternLayout">
8+
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
9+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
10+
</pattern>
11+
</layout>
12+
</appender>
13+
<!-- 日志输出级别 -->
14+
<root level="INFO">
15+
<appender-ref ref="STDOUT" />
16+
</root>
17+
</configuration>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.jsoft.test.hellospring;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

0 commit comments

Comments
 (0)