本文主要介绍了在本地搭建并运行一个Spring应用,演示了Spring依赖注入的特性
1 环境搭建
1.1 Maven依赖
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>5.0.7.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
1.2 Spring相关配置
<!--配置包扫描路径-->
<context:component-scan base-package="com.study"></context:component-scan>
<!--启用注解-->
<context:annotation-config></context:annotation-config>
1.3 主要代码
package com.study.service.impl;
import com.study.service.ProductService;
import org.springframework.stereotype.Service;
/**
* @author frankwin608
* @create 2018-07-09 23:56
* @desc 商品服务实现类
**/
@Service
public class ProductServiceImpl implements ProductService{
@Override
public String queryProductNameById(String id) {
return "Hello Kitty";
}
}