天天看点

问题记录

spring 有几种注入方式

构造函数注入

setter注入

注解注入

以下是构造函数注入方式:

import org.springframework.stereotype.Component;

@Component

public class User {

public void userName(){

System.out.println("1--------------");

}

[点击并拖拽以移动]

UserServiceImp类依赖于User类,将User类以构造函数注入的方式注入

import org.springframework.stereotype.Repository;

@Repository(value = "userServiceImp")

public class UserServiceImp {

private User user;

单元测试,验证是否真的有注入

import com.example.springbootexample.Controller.UserServiceImp;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

@RunWith(SpringRunner.class)br/>@SpringBootTest

public class SpringbootExampleApplicationTests {

@Resource(name = "userServiceImp")

UserServiceImp serviceImp;

单元测试执行结果:

SpringbootExampleApplicationTests in 7.047 seconds (JVM running for 12.118)

1--------------

mysql分库分表策略

分布式事务

Mysql join两张表后做groupby,如何将表二为空的数据,结果出来count的值为0

Join情况下,为什么要用到where1=1;

http 网络编程

继续阅读