Spring 一二事(8) - annotation 形式的 MVC
<!--
component:把一个类放入到spring容器中,该类就是一个component
在base-package指定的包及子包下扫描所有的类
-->
<context:component-scan base-package="com.lee.spring012.scan.mvc.annotation"></context:component-scan>
IStuDAO.java
package com.lee.spring012.scan.mvc.annotation;
public interface IStuDAO {
public void saveStu();
}
IStuService.java
package com.lee.spring012.scan.mvc.annotation;
public interface IStuService {
public void saveStu();
}
PersonAction.java
package com.lee.spring012.scan.mvc.annotation; import javax.annotation.Resource; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; @Controller
@Scope("prototype") // action为多例
public class PersonAction { @Resource
public IStuService stuServiceImpl; public void displaySave() {
System.out.println("mvc action: saving stu...");
stuServiceImpl.saveStu();
} }
StuDAOImpl.java
package com.lee.spring012.scan.mvc.annotation; import org.springframework.stereotype.Repository; @Repository
public class StuDAOImpl implements IStuDAO { @Override
public void saveStu() {
System.out.println("mvc dao: saving stu...");
} }
StuServiceImpl.java
package com.lee.spring012.scan.mvc.annotation; import javax.annotation.Resource; import org.springframework.stereotype.Service; @Service
public class StuServiceImpl implements IStuService { @Resource
public IStuDAO stuDAOImpl; @Override
public void saveStu() {
System.out.println("mvc service: saving stu...");
stuDAOImpl.saveStu();
} }
测试
package com.lee.spring012.scan.mvc.annotation; import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class PersonTest { @Test
public void testPersonAction() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-scan-mvc.xml");
PersonAction person = (PersonAction)context.getBean("personAction");
person.displaySave();
} }
github地址:https://github.com/leechenxiang/maven-spring001-helloworld
Spring 一二事(8) - annotation 形式的 MVC的更多相关文章
- Spring 一二事(6) - IOC MVC 简易搭建
<bean id="personAction" class="com.lee.spring008.IOC.DI.MVC.PersonAction"> ...
- Spring 一二事(7) - annotation
之前的文章大多都是一带而过,一方面比较简单,一方面不是用的注解形式 在企业开发中,主要还是使用的注解来进行开发的 1 <!-- component:把一个类放入到spring容器中,该类就是一个 ...
- Spring 一二事(10) - annotation AOP
先贴出POM的内容,这个毕竟是用的maven来简单构建的 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- Spring 一二事(9) - xml 形式的 AOP
AOP在spring中是非常重要的一个 在切面类中,有5种通知类型: aop:before 前置通知 aop:after-returning 后置通知 aop:after 最终通知 aop:af ...
- Spring 一二事(4) - 单例
spring bean配置后再默认情况下是单例的,如果需要配置可以选择 prototype, request, session和global session 在配置spring mvc的action时 ...
- Spring 一二事(1)
简单介绍一下spring,一方面带新手入入门,一方面自己也重温一下第一个小工厂先暂时不用maven,下一个会用maven来来配置 jar包只需要一个,spring版本为2.5(暂时为2.5,后续更新, ...
- Spring 一二事(5) - 依赖注入
<!-- 依赖注入的装配过程 --> <bean id="person" class="com.lee.spring007.di.xml.setter. ...
- Spring 一二事(3) - 别名
别名就是可以通过另外一个名字来访问如下,已有bean:helloWorld3,那么定义别名(alias )后,就能使用“abc”来访问 <bean id="helloWorld3&qu ...
- Spring 一二事(2)
静态工厂方法及实例工厂的使用: applicationContext.xml: <!-- factory-method 是指调用静态工厂方法 --> <bean id="h ...
随机推荐
- Ubuntu下配置jdk及maven等方法
从/etc/profile文件代码得知系统启动会把/etc/profile.d目录下面所有的.sh文件进行加载,如果在其中新建.sh文件用来设立环境变量等,系统启动后也会加载到它们.另外一种方法就是修 ...
- glassfish--服务搭建
集群配置: 1. DAS节点执行: 1)./asadmin start-domain domain1 2)./asadmin change-admin-password 3)./asadmin ena ...
- Geeks Union-Find Algorithm Union By Rank and Path Compression 图环算法
相同是查找一个图是否有环的算法,可是这个算法非常牛逼,构造树的时候能够达到O(lgn)时间效率.n代表顶点数 原因是依据须要缩减了树的高度,也叫压缩路径(Path compression),名字非常高 ...
- ios block常见的错误(二)——循环引用
这篇博文继续block的常见错误——循环引用. 循环引用是很多初学者不能察觉的,其产生的原因,是block中的代码会对对象进行强引用. 读者请阅读示例代码1,并思考示例代码1所创建的对象能否被正常销毁 ...
- 【LeetCode】75. Sort Colors (3 solutions)
Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...
- Android音乐播放器开发
今日看书,看到这个播放器,我就写了个例子,感觉还行,这个播放器能播放后缀是.MP3的音乐,这个例子在main.xml设置listView的时候,注意:android:id="@+id/and ...
- WCF中可以使用SVCUtil.exe生成客户端代理类和配置文件
1.找到如下地址“C:\Windows\System32\cmd.exe” 命令行工具,右键以管理员身份运行(视系统是否为win7 而定) 2.输入如下命令: C:\>cd C ...
- jsp地址栏传中文显示乱码解决方法
格式一: 地址栏显示格式:http://localhost:8081/Jsp2/ahref2.jsp?id=32&name=%E7%8E%8B%E4%BA%91%E9%B9%8F 1.修改To ...
- Fusion Tables 图层用于呈现 Google Fusion Tables 中包含的数据
Google Maps API 允许您使用 FusionTablesLayer 对象将 Google Fusion Tables 中包含的数据呈现为地图上的图层.Google Fusion Table ...
- 项目里面加入redis单机版 和集群版的配置
第一步: 如果你是maven项目,你直接配置就可以了,如果不是需要下载这个包 jedis包 <!-- Redis 客户端 --> <dependency> ...