SpringBoot 配置阿里云连接池

SpringBoot 配置阿里云连接池

引入jar包

 
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druid-spring-boot-starterartifactId>
            <version>1.1.17version>
        dependency>

配置application.yml文件或者是application.properties文件

#数据库配置
#数据库访问配置65p
#主数据源,默认的
#这个实例是用的MySQL版本是8.0.21
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    name: RSW
    url: jdbc:mysql://localhost:3306/***?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
    username: root
    password: ****
    # 初始化大小,最小,最大
    druid:
      initial-size: 5
      min-idle: 5
      max-active: 20
      # 配置获取连接等待超时的时间
      max-wait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 300000
import com.rsw.entity.PersonInfo;
import com.rsw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
     
    @Autowired
    private UserService userService;

    @GetMapping("/userlogin")
    public String UserLogin(){
     
        PersonInfo tom = userService.logincheck("tom", "123");
        return tom.toString();
    }
}

import com.rsw.entity.PersonInfo;
import org.apache.ibatis.annotations.Param;

public interface UserService {
     
	/**
	 * 登录检查
	 * @param username
	 * @param password
	 * @return
	 */
	PersonInfo logincheck(@Param("username") String username, @Param("password") String password);
}

import com.rsw.dao.UserDao;
import com.rsw.entity.PersonInfo;
import com.rsw.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
     

	@Resource
	private UserDao userDao;
	@Override
	public PersonInfo logincheck(String username, String password) {
     
		// TODO Auto-generated method stub
		return userDao.logincheck(username, password);
	}

}
import com.rsw.entity.PersonInfo;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface UserDao {
     
	
	/**
	 * 登录检查
	 * @param username
	 * @param password
	 * @return
	 */
	PersonInfo logincheck(@Param("username") String username, @Param("password") String password);
	
}


import java.util.Date;

/**
 * 个人信息实体类
 *
 */
public class PersonInfo {
     
	// 主键ID
	private Long userId;
	// 用户名称
	private String name;
	// 用户头像
	private String profileImg;
	// 用户邮箱
	private String email;
	// 用户性别
	private String gender;
	// 可用状态:0、被禁止 1、可用
	private Integer enableStatus;
	// 1.顾客 2.店家 3.超级管理员
	private Integer userType;
	// 创建时间
	private Date createTime;
	// 最近一次的更新时间
	private Date lastEditTime;

	public Long getUserId() {
     
		return userId;
	}

	public void setUserId(Long userId) {
     
		this.userId = userId;
	}

	public String getName() {
     
		return name;
	}

	public void setName(String name) {
     
		this.name = name;
	}

	public String getProfileImg() {
     
		return profileImg;
	}

	public void setProfileImg(String profileImg) {
     
		this.profileImg = profileImg;
	}

	public String getEmail() {
     
		return email;
	}

	public void setEmail(String email) {
     
		this.email = email;
	}

	public String getGender() {
     
		return gender;
	}

	public void setGender(String gender) {
     
		this.gender = gender;
	}

	public Integer getEnableStatus() {
     
		return enableStatus;
	}

	public void setEnableStatus(Integer enableStatus) {
     
		this.enableStatus = enableStatus;
	}

	public Integer getUserType() {
     
		return userType;
	}

	public void setUserType(Integer userType) {
     
		this.userType = userType;
	}

	public Date getCreateTime() {
     
		return createTime;
	}

	public void setCreateTime(Date createTime) {
     
		this.createTime = createTime;
	}

	public Date getLastEditTime() {
     
		return lastEditTime;
	}

	public void setLastEditTime(Date lastEditTime) {
     
		this.lastEditTime = lastEditTime;
	}

	@Override
	public String toString() {
     
		return "PersonInfo{" +
				"userId=" + userId +
				", name='" + name + '\'' +
				", profileImg='" + profileImg + '\'' +
				", email='" + email + '\'' +
				", gender='" + gender + '\'' +
				", enableStatus=" + enableStatus +
				", userType=" + userType +
				", createTime=" + createTime +
				", lastEditTime=" + lastEditTime +
				'}';
	}
}

访问http://localhost:8080/userlogin
在这里插入图片描述
集成druid成功!

你可能感兴趣的:(java,spring,boot,spring,boot,阿里云,mysql)