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

复制代码
 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 }
复制代码

 

 

 

 

复制代码
 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 }
复制代码

 

posted @   yub4by  阅读(43)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示