老师,我的logback在访问地址后出现了下面的问题

来源:3-2 logback的配置

springbaby

2020-03-13

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘areaController’ defined in file [D:\Eclipse\Eclipse for Java EE\eclipse\eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\o2o\WEB-INF\classes\com\imooc\o2o\web\superadmin\AreaController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.slf4j.Logger’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.slf4j.Logger’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

写回答

2回答

翔仔

2020-03-13

同学是不是spring版本有问题。。不知道为什么logger实现类没有被注入,不过可以这样写,在spring-dao.xml里面,第一个bean标签添加

<bean id="logger" scope="prototype" class="org.slf4j.LoggerFactory" factory-method="getLogger">
    <constructor-arg name="name" value="logger" />
</bean>

使用的时候,就可以在类里定义一个成员变量

@Autowired
private Logger logger;

然后直接用logger。

0
1
springbaby
老师,还是不行,还是错,下面是我的新的提问,里面有截图 https://coding.imooc.com/learn/questiondetail/174537.html
2020-03-14
共1条回复

翔仔

2020-03-13

同学好,感觉是缺少jar?

		<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.2.3</version>
		</dependency>

引入后,update maven project试试,如果还是不行,就引入

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
</dependency>

试试


0
2
翔仔
回复
springbaby
同学好,在你新开的问题上回答哈 http://coding.imooc.com/learn/questiondetail/174537.html
2020-03-15
共2条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程