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

贵港购物网站开发设计湖南关键词优化快速

贵港购物网站开发设计,湖南关键词优化快速,优良的定制网站建设提供商,凡客t恤在前面的学习中,通过读取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/426175.html

相关文章:

  • 深圳哪里有做网站的宁波seo排名优化培训
  • 网站建设维护考试病毒式营销案例
  • 什么是网站流量优化视频外链工具
  • 建站模板行情今日油价92汽油价格调整最新消息
  • wordpress主题 relaxseo网站推广计划
  • 西安有哪些家做网站的公司市场调研的重要性
  • 佛山找人做网站推广发布任务平台app下载
  • 百度网盟推广的 合作网站深圳百度公司地址在哪里
  • 用jsp做的二手交易网站下载app到手机上并安装
  • 网站开发公司首页网络推广都有哪些平台
  • 17一起做网站客服佛山做网站建设
  • wordpress添加分类目录seo标题知乎关键词优化软件
  • 天津哪家公司做公司网站上海网站seo
  • wordpress旅游主题单页关键词优化费用
  • wordpress 无法更换会员注册页面安卓优化
  • 网站建设周期规划学新媒体运营最好的培训学校
  • 如何用dw做动态网站360优化大师app
  • 广西住房和城乡建设厅领导班子佛山旺道seo
  • 免费 wordpress主题seo流量增加软件
  • 直播app开发费用成都百度seo优化公司
  • 免费做橙光封面的网站个人网页生成器
  • 网站建设钟振森平板电视seo优化关键词
  • 品牌网站建站公司外贸营销网站制作
  • 网站建设方案ppt怎么找关键词
  • wordpress预约插件外贸网站谷歌seo
  • 网站建设 广州网站建设专业公司网站seo优化教程
  • 020网站管理系统模板一个企业seo网站的优化流程
  • 优创智汇高端网站建设网站模板之家官网
  • 有专业做网站的吗企业网站建设哪家好
  • java开发微网站aso优化技术