1 # Set root category priority to INFO and its only appender to CONSOLE.
 2 #log4j.rootCategory=INFO, CONSOLE            debug   info   warn error fatal
 3 log4j.rootCategory=info, CONSOLE, LOGFILE
 4 
 5 # Set the enterprise logger category to FATAL and its only appender to CONSOLE.
 6 log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
 7 
 8 # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
 9 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
10 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
11 log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
12 
13 # LOGFILE is set to be a File appender using a PatternLayout.
14 log4j.appender.LOGFILE=org.apache.log4j.FileAppender
15 log4j.appender.LOGFILE.File=d:\axis.log
16 log4j.appender.LOGFILE.Append=true
17 log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
18 log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:aop="http://www.springframework.org/schema/aop"
 6        xmlns:tx="http://www.springframework.org/schema/tx"
 7        xsi:schemaLocation="
 8         http://www.springframework.org/schema/beans
 9         http://www.springframework.org/schema/beans/spring-beans.xsd
10         http://www.springframework.org/schema/context
11         http://www.springframework.org/schema/context/spring-context.xsd
12         http://www.springframework.org/schema/aop
13         http://www.springframework.org/schema/aop/spring-aop.xsd
14         http://www.springframework.org/schema/tx
15         http://www.springframework.org/schema/tx/spring-tx.xsd
16 ">
17 
18     <!--开启注解所需的组件扫描,期望spring只负责处理service和dao;controller用springMVC处理-->
19     <context:component-scan base-package="com.haifei">
20         <!--配置哪些注解不被扫描-->
21         <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
22     </context:component-scan>
23 
24 </beans>
 1 package com.haifei.service.impl;
 2 
 3 import com.haifei.domain.Account;
 4 import com.haifei.service.AccountService;
 5 import org.springframework.stereotype.Service;
 6 
 7 import java.util.List;
 8 
 9 /**
10  * service接口实现类-账户
11  */
12 @Service("accountService") //将AccountServiceImpl类交给spring的IOC容器进行管理
13 public class AccountServiceImpl implements AccountService {
14 
15     @Override
16     public List<Account> findAll() {
17         System.out.println("业务层:查询所有账户");
18         return null;
19     }
20 
21     @Override
22     public void saveAccount(Account account) {
23         System.out.println("业务层:保存账户信息");
24     }
25 
26 }

SSM17.2【SSM框架整合--搭建和测试Spring的开发环境】_spring

 

 SSM17.2【SSM框架整合--搭建和测试Spring的开发环境】_SSM_02

 

 

 1 package com.haifei.test;
 2 
 3 import com.haifei.service.AccountService;
 4 import org.junit.Test;
 5 import org.springframework.context.ApplicationContext;
 6 import org.springframework.context.support.ClassPathXmlApplicationContext;
 7 
 8 public class TestSpring {
 9 
10     @Test
11     public void run1(){
12         //加载配置文件
13         ApplicationContext app = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
14         //获取对象
15         AccountService service = (AccountService)app.getBean("accountService");
16         //调用方法
17         service.findAll(); //业务层:查询所有账户
18     }
19 
20 }

SSM17.2【SSM框架整合--搭建和测试Spring的开发环境】_xml_03