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

贵港购物网站开发设计北京网站设计公司

贵港购物网站开发设计,北京网站设计公司,怎么做网站才能被收购,专业定制网站建设智能优化在前面的学习中,通过读取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/77855.html

相关文章:

  • 泰安企业建站公司服务中国刚刚发生的新闻
  • 做网站广告多少钱seo怎么去优化
  • 什么叫静态网站网络营销网站平台有哪些
  • 服务器上网站建设高德北斗导航
  • 门头沟做网站公司百度指数查询app
  • wordpress 深色主题seox
  • 牛商网营销型网站建设如何做网络营销
  • 昆明高端网站建设郑州客串seo
  • php企业网站举例说明seo
  • 小型的企业网站网络黄页推广软件
  • 通过模版做网站百度收录提交申请
  • 电子口岸网站做资料库买卖交易平台
  • 网站后台首页品牌seo是什么
  • 比分网站怎么做关键词在线采集
  • wordpress需要 伪静态安徽百度关键词优化
  • 网站建设狼雨搭建网站步骤
  • 空间信息网站优化推广公司哪家好
  • wordpress换域名主页不能访问seo专员是做什么的
  • 贵州网站建设gzzctyi搜狗推广平台
  • 软件二次开发怎么弄网站优化推广软件
  • 产品设计主要学什么seo变现培训
  • 上海建设官方网站自媒体服务平台
  • 有服务器自己怎么做网站搜索引擎站长平台
  • 营销型网站建设费用怎么这么大网站快速优化排名软件
  • 做网站需要代码么外链链接平台
  • 培训网站制作网络推广引流有哪些渠道
  • 政府网站维护方案百度高级搜索页面
  • 南宁专业网站建设网站下载免费软件
  • word后的网站引用怎么做营销平台建设
  • 学做ppt的网站什么叫百度竞价推广