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

商丘交友网站开发公司宁波seo推广推荐公司

商丘交友网站开发公司,宁波seo推广推荐公司,上海装修公司排名大全,深圳做网站企业在前面的学习中,通过读取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.dtcms.com/wzjs/354964.html

相关文章:

  • 广州网站建设招标网站优化招聘
  • 新闻写作网站厦门百度广告
  • wordpress文章发布不了南京seo圈子
  • 网站建议反馈应该怎么做加入网络营销公司
  • 苏州个人网站建设如何做好网站的推广工作
  • 做网站开发的东莞关键词seo优化
  • 什么主题的网站容易做网络建站公司
  • 南通网站建设服务友情链接什么意思
  • wordpress 顶部白条什么是搜索引擎优化的核心
  • 佛山网站哪家最专业网络推广网上营销
  • 网站建设价目网站排名推广推荐
  • 宁波建设网站公司网站推广seo优化
  • 深圳网站设计推荐刻关键词热度分析
  • 创建自己的网站有什么用提高网站排名的软件
  • 免费商城网站建设新闻软文怎么写
  • 重庆模板网站建设费用免费seo关键词优化服务
  • 保健品 东莞网站建设百度一下照片识别
  • 郑州企业网站排名优化公司苏州seo排名公司
  • 网站开发后是不是下挂到域名seo怎么优化网站排名
  • 上海市建设质量协会网站今日广东头条新闻
  • 无锡网站建设选众鼎360搜索优化
  • wordpress 时间格式搜索引擎外部链接优化
  • 海外cdn如何优化关键词搜索排名
  • 响应式网站模板滚动条百度最新推广产品
  • 厦门 网站开发线上推广活动有哪些
  • 服饰网站模板大数据免费查询平台
  • 广告设计公司服务承诺seo排名优化
  • 郑州建设局网站cba目前排名
  • 做微电网的公司网站百度老旧版本大全
  • net网站同时支持 生成静态文件和伪静态头条广告入口