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 ...
随机推荐
- UVA 10090 Marbles(扩展欧几里得)
Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...
- qtp:vbs基础教程
◎Vbs脚本编程简明教程之中的一个-为什么要使用Vbs? 在Windows中,学习计算机操作或许非常easy,可是非常多计算机工作是反复性劳动,比如你每周或许须要对一些计算机文件进行复制.粘贴.改名 ...
- Sql_Handle and Plan_Handle Explained
For batches, the SQL handles are hash values based on the SQL text. For database objects such as sto ...
- Js判断出生年月填写的 是否正确
var r = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29 ...
- Windows10关闭SearchUI.exe进程的方法
目前唯一的方法只能通过修改Cortana目录的方法来禁止Cortana 路径:C:\Windows\SystemApps\Microsoft.Windows.Cortana_***
- 一致性 hash 算法( consistent hashing )(转)
consistent hashing 算法早在 1997 年就在论文 Consistent hashing and random trees 中被提出,目前在 cache系统中应用越来越广泛: 1 基 ...
- libevent个人理解
1.利用了前置声明来在c语言的基础上进行封装操作.即在include目录下防止event.h等头文件,在这些头文件中只暴露struct的声明却不暴露其定义,对于如event_base等结构的操作均使用 ...
- Redis学习(8)-redis其他特性
消息订阅与发布 subscribe Channel:订阅频道 psubscribe channel*:批量订阅频道:例如:psubscribe S*,订阅以S开头的频道. publish channe ...
- HDUOJ------2398Savings Account
Savings Account Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 能让你聪明的工作DEAL四法则,来自《每周工作四小时》书籍
来自书籍<每周工作四小时>,作者蒂莫西·费里斯(Tim Ferriss,昵称:蒂姆) 能让你聪明的工作DEAL四法则: 第一步:D——定位(Definition) 第二步:E——精简( ...