结构没有问题。 spring-boot可以扫描UserMapper,但不能扫描UserService。我尝试提供UserService @Mapper组件,然后可以对其进行扫描。但是我不知道如何使用其他方法进行扫描。我尝试了@Service,但没有用。
package com.mywebprojet.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MywebprojectApplication {
public static void main(String[] args) {
SpringApplication.run(MywebprojectApplication.class, args);
}
}
package com.mywebprojet.springboot.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.mywebprojet.springboot.entity.User;
import com.mywebprojet.springboot.mapper.UserMapper;
import com.mywebprojet.springboot.service.UserService;
@RestController
@RequestMapping(value = "user")
public class UserController {
@Autowired
private UserMapper userMapper;
@Autowired
private UserService userService;
}
package com.mywebprojet.springboot.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.mywebprojet.springboot.entity.User;
@Service
public interface UserService{
void insert(User user);
}
答案 0 :(得分:0)
您应该编写UserService实现,并使用@Service(而不是接口)对其进行注释。例如:
@Service
public class UserServiceImpl implements UserService {
@Override
public void insert(User user) {
// Implementation
}
}在此处输入代码