factorytest,spring入门详解

伏羲号

factorytest,spring入门详解?

一、Spring概述

factorytest,spring入门详解

Spring是一个轻量级的DI/IOC和AOP的容器框架

  轻量级:简单好用,通常来说功能不强大(但spring功能强大)

  DI(依赖注入):动态的向某个对象提供它所需要的其他对象,也可以为对象的属性字段赋值。(依赖注入又分为xml注入和注解注入)

  IOC(控制翻转):由spring控制对象的生命周期(创建,销毁)

  AOP(面向切面编程):解决重复代码。将相同的逻辑抽取出来,即将业务逻辑从应用服务中分离出来。然后以拦截的方式作用在一个方法的不同位置。

二、Spring入门

1.引入库

导包的时候注意,现在使用Spring,要完成最小导包,即:需要什么jar包,我们就导入什么jar包,用到了其他功能,再添加相应jar包。这个对认识框架的包是非常有帮助的:

2.导入Spring配置文件

1. 在classpath的根目录下新建一个applicationContext.xml配置文件,文件名可以自定义,但是通常使用ApplicationContext这个名字:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/Beans/spring-beans.xsd">

<bean id="..." class="...">

<!-- collaborators and configuration for this bean go here -->

</bean>

</beans>

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

3.编写逻辑代码

public class MyBean {

public void hello(){

System.out.println("hello spring...");

}

}

1

2

3

4

5

6

1

2

3

4

5

6

4.将这个类交给Spring去管理即注册到Spring容器中

在配置文件中将这个Java类交给Spring管理。在applicationContext.xml中配置

<beans ...>

<bean id="myBean" class="cn.itsource._01_hello.MyBean"></bean>

</beans>

1

2

3

4

1

2

3

4

5.Spring容器的实例化

Spring容器对象有两种:BeanFactory和ApplicationContext(推荐使用)

BeanFactory

@Test

public void testHelloSpring1() throws Exception {

/**

*我们第一步是要启动框架,而启动框架则需要拿到Spring的核心对象

*咱们学习的第一个核心对象是BeanFactory : 顾名思义,这是一个创建Bean的工厂

*而Bean工厂创建对象又必需拿到配置文件中的数据

*因为:我们的第一步读取配置文件,拿到BeanFactory工厂

*/

//第一步:读取资源文件

Resource resource = new ClassPathResource("applicationContext.xml");

//第二步:拿到核心对象 BeanFactory

BeanFactory factory = new XmlBeanFactory(resource);

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

ApplicationContext(推荐使用)

@Test

public void testHelloSpring2() throws Exception {

/**

*我们第一步是要启动框架,而启动框架则需要拿到Spring的核心对象

*咱们学习的第一个核心对象是BeanFactory : 顾名思义,这是一个创建Bean的工厂

*而Bean工厂创建对象又必需拿到配置文件中的数据

*因为:我们的第一步读取配置文件,拿到BeanFactory工厂

*/

//加载工程classpath下的配置文件实例化

String conf = "applicationContext.xml";

ApplicationContext factory = new ClassPathXmlApplicationContext(conf);

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

6.获取对象方式

方式一:通过id直接拿到相应的Bean对象

//通过xml中配置的id拿到对象

MyBean bean = (MyBean)factory.getBean("myBean");

System.out.println(bean);

1

2

3

4

1

2

3

4

方式二:通过id与对象的Class对象拿到Bean对象(推荐使用)

//通过id与对象的class拿到Bean对象

MyBean bean = factory.getBean("myBean",MyBean.class);

System.out.println(bean);

1

2

3

4

1

2

3

4

三、Spring依赖注入

1.xml注入

顾名思义:在xml中进行配置,但是这种方式必须有对应的setter方法,所有这种注入方式又称之为属性注入或setter方法注入

public class MyBean{

private OtherBean otherBean;

public void hello(){

otherBean.hello();

}

public void setOtherBean(OtherBean otherbean){

this.OtherBean = OtherBean

}

}

1

2

3

4

5

6

7

8

9

10

1

2

3

4

5

6

7

8

9

10

public class OtherBean{

public void hello(){

System.out.println("otherbean hello");

}

}

1

2

3

4

5

6

1

2

3

4

5

6

//xml配置:

<bean id="otherBean" class="cn.itsource.bean.OtherBean"></bean>

<bean id="myBean" class="cn.itsource.bean.MyBean">

<property name="otherBean" ref="otherBean"></property>

</bean>

1

2

3

4

5

6

1

2

3

4

5

6

2.注解注入

顾名思义:通过注解实现注入,这种方式可以将注解写在setter方法上,也可以写在字段上,如果写在字段上可以不需要setter方法

2.1方案一:使用@Autowired

@Autowired为Spring提供的注解

public class MyBean{

@Autowired

private OtherBean otherBean;

public void hello(){

otherBean.hello();

}

}

public class OtherBean{

public void hello(){

System.out.println("otherbean hello");

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

1

2

3

4

5

6

7

8

9

10

11

12

13

14

//xml配置:

<bean id="otherBean" class="cn.itsource.bean.OtherBean"></bean>

<bean id="myBean" class="cn.itsource.bean.MyBean"></bean>

1

2

3

1

2

3

2.2方案二:使用@Resource

public class MyBean{

@Resource

private OtherBean otherBean;

public void hello(){

otherBean.hello();

}

}

public class OtherBean{

public void hello(){

System.out.println("otherbean hello");

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

1

2

3

4

5

6

7

8

9

10

11

12

13

14

2.3@Autowired和@Resource区别

@Autowired:默认类型匹配再按照名字匹配

@Resource:默认按照名字匹配然后按照类型匹配

fat在工厂是什么意思?

意思是:工厂验收试验

“FAT”是“Factory Acceptance Test”的缩写,意思是“工厂验收试验”。

FAT是文件配置表(英语:File Allocation Table,首字母缩略字:FAT),是一种由微软发明并拥有部分专利.

手机进入FactoryMode按哪个恢复出厂设置?

full test:全部测试?

item test:自定义测试?

test report:测试报告ersion:擦除reboot:重启先ersion吧,然后reboot试试。擦除数据后,联系人等信息就没了吧

FAT模式和FIT模式的区别?

FAT和FIT都是对计算机系统适合性的测试模式,它们之间的区别在于侧重点不同,实际操作效果不同。

1. FAT模式(Factory Acceptance Test,出厂验收测试):指的是在制造商工厂内进行的一项测试,主要目的是验证设备能否按照客户订单的要求制造完成。在此过程中,制造商将使用一系列的测试程序和工具测量、评估并确认设备是否符合特定的技术规格,以便于在设备出厂之前进行客户验收。

2. FIT模式(Field Integration Test,现场整合测试):是指将制造商交付的设备或软件部署到现场之后进行的一项测试,主要目的是验证设备或软件能否按照客户要求正常运行。在此过程中,现场工程师将对设备或软件在现场的安装、配置、设置、运行和维护等方面进行测试和评估,以确保设备或软件能够实现客户期望的功能和性能需求。

因此,FAT和FIT都是用来检验设备或软件的适合性和可靠性的测试模式,但它们的侧重点是不同的。FAT更关注于设备的生产制造过程的质量保证,而FIT则更关注于设备或软件的实际操作效果,以确保它们能够完全满足客户的要求。

mode怎么恢复出厂设置?

选择wipe data/factory reset 按菜单键 选择yes.....点菜单键恢复出厂设置 然后选择reboot aystem now 按菜单键重新启动 这是恢复出厂的方法 !注意:资料会被销毁!

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (暂无评论,58人围观)

还没有评论,来说两句吧...