当前位置: 首页 > wzjs >正文

广州做网站开发营销推广文案

广州做网站开发,营销推广文案,重庆企业网站推广报价,网站 文件验证背景 spring框架的一个核心功能是IOC,就是将Bean初始化加载到容器中,Bean是如何加载到容器的,可以使用spring注解方式或者spring XML配置方式。 spring注解方式直接对项目中的类进行注解,减少了配置文件内容,更加便于…

背景

spring框架的一个核心功能是IOC,就是将Bean初始化加载到容器中,Bean是如何加载到容器的,可以使用spring注解方式或者spring XML配置方式。

spring注解方式直接对项目中的类进行注解,减少了配置文件内容,更加便于管理,使用注解可以大大提高了开发效率!

注解

@Component表示一个带注释的类是一个“组件”,成为Spring管理的Bean。当使用基于注解的配置和类路径扫描时,这些类被视为自动检测的候选对象。同时@Component还是一个元注解。

@Controller组合注解(组合了@Component注解),应用在MVC层(控制层),DispatcherServlet会自动扫描注解了此注解的类,然后将web请求映射到注解了@RequestMapping的方法上。

@Service组合注解(组合了@Component注解),应用在service层(业务逻辑层)。

@Reponsitory组合注解(组合了@Component注解),应用在dao层(数据访问层)。

测试代码:

被@Component注解的类UserDaoImpl:

package com.annotation.dao.impl;import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;import com.annotation.dao.interfaces.InterfaceUserDao;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-03-24* @version   1.0* @brief     注解方式标注Bean,命名为“userDaoDao”,如果没有命名,则默认为类名首字母小写,即“userDaoImpl”。* @history   name*            date*            brief*/
@Component(value = "userDao01")
@Scope(value = "prototype")
@Lazy(value = false)
public class UserDaoImpl implements InterfaceUserDao {public UserDaoImpl() {System.out.println("类的构造方法");}@Overridepublic void print() {System.out.println("UserDaoImpl类实例,继承接口InterfaceUserDao");}@PostConstructpublic void init() {System.out.println("UserDaoImpl类init方法,在构造方法之后调用");}@PreDestroypublic void destroy() {System.out.println("UserDaoImpl类destroy方法,在Bean销毁之前调用");}
}

注解类实现的接口InterfaceUserDao :

package com.annotation.dao.interfaces;/*** @copyright 2003-2024* @author    qiao wei* @date      2024-12-22* @version   1.0* @brief     * @history   name*            date*            brief*/
public interface InterfaceUserDao {void print();
}

测试验证:

package com.annotation.dao.impl;import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.annotation.dao.interfaces.InterfaceUserDao;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-12* @version   1.0* @brief     * @history   name*            date*            brief*/
class UserDaoImplTest {@Testpublic void test01() {ClassPathXmlApplicationContext context =new ClassPathXmlApplicationContext("./xml/annotation/applicationContext.xml");InterfaceUserDao userDao = context.getBean("userDao01", InterfaceUserDao.class);userDao.print();context.close();}
}

读取的配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd"><!--  进行注解扫描。扫描制定的包及其子包。  --><context:component-scan base-package="com.annotation" />
</beans>

运行结果:

http://www.dtcms.com/wzjs/100053.html

相关文章:

  • 内容展示型网站特点百度信息流投放技巧
  • 东旭网站建设郑州网站建设公司排行榜
  • 临夏市建设局网站qq营销软件
  • ps做网站的分辨率多少钱苏州网站制作推广
  • 在地区做网站怎么赚钱百度广告太多
  • 翡翠原石网站首页怎么做seo优化推广技巧
  • 成都专业做网站公司哪家好网站排名查询站长之家
  • 建设独立网站的公司深圳大鹏新区葵涌街道
  • 建站系统社区怎么做推广和宣传平台
  • 教学网站建设论文信息发布网站有哪些
  • 做问卷网站好北京、广州最新发布
  • 好网站你知道重庆seo排名外包
  • 50m专线做视频网站万网域名查询
  • 有网站前台如何做后台宁波最好的推广平台
  • 深圳网站开发服务朋友圈营销广告
  • 企业建站需要多少钱杭州明开seo
  • 做六合彩网站营销外包公司
  • 市建委官方网站最好用的免费建站
  • 美国网站加速器成都seo培训班
  • 大连做网站绍兴厂商广州网页定制多少钱
  • 做nba直播网站有哪些百度排名优化工具
  • win2003怎么做网站企业邮箱哪个好
  • 天津市房地产官网长沙seo运营
  • 服务器做网站哪个系统好短视频运营是做什么的
  • 室内设计平面图素材优化大师官网下载安装
  • 广告公司策划案seoul是什么意思中文
  • 杭州设计公司网站排名百度seo优化收费标准
  • 珠海高端网站制作在线外链发布工具
  • 佛山网站建设全方位服务百度网盘官方下载
  • 公建设计网站关键词排名软件