package com.example.springboot;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
@Controller
public class UserController {
@Autowired
private JdbcTemplate jdbcTemplate;
@RequestMapping(value = "/getUsers",method = RequestMethod.GET)
@ResponseBody
/*
* List 里的对象是Map对象,而Map对象是
* 由一个String类型的键和Object类型的值组成
* */
public List<Map<String,Object>> getUsers(){
String sql="select * from user";//SQL查询语句
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql);
return list;
}
}
出问题了:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.6)
2022-04-11 17:12:26.060 INFO 2404 --- [ main] c.e.springboot.SpringbootApplication : Starting SpringbootApplication using Java 11.0.14.1 on LAPTOP-P7V8I31O with PID 2404 (C:\Users\LIINn\Desktop\springboot\target\classes started by LIINn in C:\Users\LIINn\Desktop\springboot)
2022-04-11 17:12:26.062 INFO 2404 --- [ main] c.e.springboot.SpringbootApplication : No active profile set, falling back to 1 default profile: "default"
2022-04-11 17:12:27.113 INFO 2404 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-04-11 17:12:27.114 INFO 2404 --- [ main] o.a.catalina.core.AprLifecycleListener : Loaded Apache Tomcat Native library [1.2.32] using APR version [1.7.0].
2022-04-11 17:12:27.114 INFO 2404 --- [ main] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
2022-04-11 17:12:27.114 INFO 2404 --- [ main] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2022-04-11 17:12:27.116 INFO 2404 --- [ main] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.1.1n 15 Mar 2022]
2022-04-11 17:12:27.125 INFO 2404 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-04-11 17:12:27.125 INFO 2404 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-04-11 17:12:27.258 INFO 2404 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-04-11 17:12:27.258 INFO 2404 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1150 ms
2022-04-11 17:12:27.298 WARN 2404 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.jdbc.core.JdbcTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2022-04-11 17:12:27.300 INFO 2404 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-04-11 17:12:27.313 INFO 2404 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-04-11 17:12:27.328 ERROR 2404 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field jdbcTemplate in com.example.springboot.UserController required a bean of type 'org.springframework.jdbc.core.JdbcTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.jdbc.core.JdbcTemplate' in your configuration.
Process finished with exit code 1