Spring boot 弹簧靴没有自动接线
有人能告诉我我做错了什么吗,我正在尝试开发一个小应用程序,但我只是不能在控制器中自动连接一个类,我一直在研究,我知道对于Autowire works,我的类必须在@SpringBootApplication注释的子包中,或者我应该在@ComponentScan注释中指定我的类的包,但不管我做什么,我仍然会得到相同的错误: 这是我的项目结构: 控制器:Spring boot 弹簧靴没有自动接线,spring-boot,autowired,Spring Boot,Autowired,有人能告诉我我做错了什么吗,我正在尝试开发一个小应用程序,但我只是不能在控制器中自动连接一个类,我一直在研究,我知道对于Autowire works,我的类必须在@SpringBootApplication注释的子包中,或者我应该在@ComponentScan注释中指定我的类的包,但不管我做什么,我仍然会得到相同的错误: 这是我的项目结构: 控制器: package net.spring.auditoria.bll; import org.slf4j.Logger; import org.sl
package net.spring.auditoria.bll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class AuditoriaController {
@Autowired
private AuditoriaManagement am;
private final Logger LOGGER = LoggerFactory.getLogger(AuditoriaController.class);
@GetMapping("/auditar")
public String auditar() {
LOGGER.info("auditar()");
return "main";
}
}
因为AuditoriaManagement不是Springbean或组件
因为AuditoriaManagement不是Springbean或组件
你是对的,我什么时候应该使用@Component注释?是的,或者像@Bean、@Controller、@Component、@Repository等。@Jose:@Component是组件的通用原型@Servcie、@Repository、@Controller是从@Component:@Service、@Controller、@Repository={@Component+一些更特殊的功能}扩展而来的。你是对的,我什么时候应该使用@Component注释?是的,或者类似于@Bean、@Controller、@Component、@Repository等等。@Jose:@Component是组件的通用原型@Servcie、@Repository、@Controller从@Component:@Service、@Controller、@Repository={@Component+一些更特殊的功能}扩展而来
package net.spring.auditoria.bll;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class AuditoriaController {
@Autowired
private AuditoriaManagement am;
private final Logger LOGGER = LoggerFactory.getLogger(AuditoriaController.class);
@GetMapping("/auditar")
public String auditar() {
LOGGER.info("auditar()");
return "main";
}
}