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的注解节省代码,看情况选择