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

深圳做网站做公司网站的公司/洛阳市网站建设

深圳做网站做公司网站的公司,洛阳市网站建设,网上快速学做网站,sharepoint网站开发在前面的学习中,通过读取xml文件将类加载,或他通过xml扫描包,将包中的类加载。无论如何都需要通过读取xml才能够进行后续操作。 在此创建配置类。通过对配置类的读取替代xml的功能。 配置类就是Java类,有以下内容需要执行&#…

在前面的学习中,通过读取xml文件将类加载,或他通过xml扫描包,将包中的类加载。无论如何都需要通过读取xml才能够进行后续操作。

在此创建配置类。通过对配置类的读取替代xml的功能。

配置类就是Java类,有以下内容需要执行:

1:对类使用注解@Configuration标注。

2:使用注解@ComponentScan扫描包,将包中的类加载。

 配置类SpringConfig:

package com.annotation.config;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-18* @version   1.0* @brief     * @history   name*            date*            brief*/
@Configuration// <context:component-scan base-package="com.annotation.thirdjar" />
@ComponentScan(basePackages = {"com.annotation.thirdjar", "com.itheima.dao.impl"})
public class SpringConfig {
}

在这里配置类加载了两个包,两个包里的类都可以被调用。

加载配置类:

package com.annotation.config;import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;import static org.junit.jupiter.api.Assertions.*;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-18* @version   1.0* @brief     * @history   name*            date*            brief*/
class SpringConfigTest {@Testpublic void test01() {ApplicationContext context =new AnnotationConfigApplicationContext(SpringConfig.class);String date = (String) context.getBean("getDateInStringFormat");System.out.println(date);}
}

运行结果显示当前年月日及时间。

调用的类如下:

package com.annotation.thirdjar;import java.util.Date;import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-16* @version   1.0* @brief     * @history   name*            date*            brief*/
@Component(value = "factory")
public class DateFactory {public DateFactory() {}@Bean(name = "getDate001")public Date getDate() {return new Date();}
}

package com.annotation.thirdjar;import java.text.SimpleDateFormat;
import java.util.Date;import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;/*** @copyright 2003-2025* @author    qiao wei* @date      2025-04-15* @version   1.0* @brief     * @history   name*            date*            brief*/
@Component
public class DateFormat02 {public DateFormat02() {}/*** @author  qiao wei* @brief   带参数。基本类型使用@Value,引用类型使用@Qualifier。* @param   * @return  * @throws  * @history name*          date*          brief*/@Bean(value = "simpleDateFormat")public SimpleDateFormat getSimpleDateFormat(@Value ("yyyy-MM-dd HH:mm:ss z") String format) {return new SimpleDateFormat(format);}/*** @author  qiao wei* @brief   方法带参数的注解Bean。* @param   * @return  * @throws  * @history name*          date*          brief*/@Bean(value = "dateFormatInString")public String getDateFormat(@Value(DATE_FORMAT) String format,@Qualifier(value = "factory") DateFactory dateFactory) {return new SimpleDateFormat(format).format(dateFactory.getDate());}/*** @author  qiao wei* @brief   方法带参数的注解Bean。注意与test02相比,参数date调用的是类Factory的getDate方法的返回值。* @param   * @return  * @throws  * @history name*          date*          brief*/@Bean(value = "getDateInStringFormat")public String getDateFormat(@Value(DATE_FORMAT) String format,@Qualifier(value = "getDate001") Date date) {return new SimpleDateFormat(format).format(date);}private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}

http://www.whsansanxincailiao.cn/news/32026098.html

相关文章:

  • 全球域名查询/优化seo哪家好
  • 教做凉拌菜的视频网站/林哥seo
  • 网站制作方案模板/销售找客户的app
  • 桂林工作网招聘/西安seo服务公司排名
  • css 网站模板/响应式网站模板的应用
  • 个人网站的制作教程/经典软文案例分析
  • 阿里巴巴上面可以做网站/google官网
  • 网站做的好不好/杭州seo顾问
  • 宁波做网站/河南最新消息
  • 贵州建设厅造价信息网站/网络推广外包内容
  • 在线网页客服/东莞市网络seo推广服务机构
  • 怎么做网站转让机制/免费推广产品的网站
  • 高端电商网站开发/百度公司在哪里
  • 网站的建设方面如何写/seo点击排名工具有用吗
  • 个人网站建设方案书使用几号纸/seo优化师
  • 班级网站开发毕业论文参考文献/日本域名注册
  • 医院网站建设 价格/淄博头条新闻今天
  • php网站开发总结文档/如何使用网络营销策略
  • 网站外链分析怎么做/网上推广怎么弄?
  • 商丘网站建设.com/茂名百度seo公司
  • 泉州做企业网站/济南seo优化外包服务
  • 用web做的网站怎么合成一个/论坛推广
  • 专业团队张益达图片/seo效果分析
  • 阿里网站如何做接入/国外网站制作
  • 无锡做网站企业/百度大数据查询平台
  • 开发一个交易平台需要多少钱/电脑优化系统的软件哪个好
  • 长沙做网站微联讯点很好/营销渠道策略
  • 万网域名查询工具/seo网站推广的主要目的
  • 做网站需要学什么专业/优化网站关键词的技巧
  • 网站规划与建设/企业网站推广有哪些