zoukankan      html  css  js  c++  java
  • spring注解和jdk注解简单概述

    spring的注解

    @Autowired@Qualifier

    配合applicationContext.xml

    1     <bean id="myNewsAction" class="news.action.NewsAction" scope="prototype"></bean>
    2     
    3     <bean id="myNewsService" class="news.service.NewsServiceImpl" scope="prototype"></bean>
    4     
    5     <bean id="myNewsDao" class="news.dao.NewsDaoImpl" scope="prototype"></bean> 

    完成

    jdk的注解

    @Controller @Service @Repository

    @Controller这个是注入service的实例

    1 @Controller("myNewsAction")
    2 @Scope("prototype")
    3 public class NewsAction extends ActionSupport {
    4     
    5     private NewsService ns;

    @Service是注入dao实例的

    1 @Service("myNewsService")
    2 @Scope("prototype")
    3 public class NewsServiceImpl implements NewsService {
    4 
    5     private NewsDao nd;

    @Repository这个是注入SessionFactory实例的

    1 @Repository("myNewsDao")
    2 @Scope("prototype")    
    3 public class NewsDaoImpl implements NewsDao {
    4     
    5      private SessionFactory sf;

    两种注解都有各的好处,spring的注解可读性强,jdk的注解节省代码,看情况选择

  • 相关阅读:
    一起ORA-00028案例的处理过程
    Preferences偏好设置
    Snap Settings对齐设置
    Graphics Emulation图形模拟
    Network Emulation(网格模拟)
    Selection
    Edit编辑
    Build Settings 构建设置
    Player Settings-PC
    Build Settings发布设置
  • 原文地址:https://www.cnblogs.com/Sosowu/p/5993019.html
Copyright © 2011-2022 走看看