Spring,SpringMVC基础知识点 面试必会

Spring

体系结构:

UTOOLS1587047735756.png

特点:

UTOOLS1587047716866.png

 

Ioc

控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。其中最常见的方式叫做依赖注入(Dependency Injection,简称DI),还有一种方式叫“依赖查找”(Dependency Lookup)

SpringIOC约束文件头(XML文件)

<?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">
</beans>
​
//测试类
//解析XML文件
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
//获取AccoutService类
IAccountService as = ac.getBean("accountService",IAccountService.class);
//调用方法
List<Account> list = as.findAllAccount();
​

SpringIOC注解

@Component @Controller @Service @Repository == <bean id="" class="">

@Autowired @Qualifier @Resource @Value == <property name="" ref="">

<property name="" value="">

@Scope == <bean id="" class="" scope="">

@PostConstruct @PreDestroy == <bean id="" class="" init-method="" destroy-method="" />

新注解

@Configuration 用于指定当前类是一个 spring 配置

@Bean 该注解只能写在方法上,表明使用此方法创建一个对象,并且放入 spring 容器。

@PropertySource 用于加载.properties 文件中的配置。例如我们配置数据源时,可以把连接数据库的信息写到 properties 配置文件中,就可以使用此注解指定 properties 配置文件的位置。

 

注:1.Bean 缓存池为 HashMap实现

2.singleton:单例模式(多线程下不安全) prototype:原型模式每次使用时创建

AOP

AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期间动态代理实现程序功能的统一维护的一种技术。

SpringAOP约束文件头(XML文件)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop.xsd">
</beans>
​

SpringAOP注解

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" 
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 
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd">
​

JdbcTemplate

(spring-jdbc-5.0.2.RELEASE.jar ,spring-tx-5.0.2.RELEASE.jar)

配置 C3P0 数据源

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql:///spring_day02"></property>
<property name="user" value="root"></property>
<property name="password" value="1234"></property>
</bean>
​

配置 DBCP 数据源

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql:// /spring_day02"></property>
<property name="username" value="root"></property>
<property name="password" value="1234"></property>
</bean>
​

配置 spring 内置数据源

spring 框架也提供了一个内置数据源,我们也可以使用 spring 的内置数据源,它就在
spring-jdbc-5.0.2.REEASE.jar 包中:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql:///spring_day02"></property>
<property name="username" value="root"></property>
<property name="password" value="1234"></property>
</bean>
​

 

核心包

UTOOLS1587047799005.png

常用注解:

UTOOLS1587047813503.png

第三方结合包:

UTOOLS1587047828617.png

 

 

SpringMVC

流程图

UTOOLS1587048575263.png

常用注解:

UTOOLS1587048602228.png

SpringBoot

Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭 建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的 配置。特点:

  1. 创建独立的 Spring 应用程序

  2. 嵌入的 Tomcat,无需部署 WAR 文件

  3. 简化 Maven 配置

  4. 自动配置 Spring

  5. ᨀ供生产就绪型功能,如指标,健康检查和外部配置

  6. 绝对没有代码生成和对 XML 没有要求配置 [1]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值