idea Could not autowire. No beans of type found

sfbayscott2008 2019-07-01 04:17:58
今天在学习spring boot的似乎还遇到这个,不知道哪里出错了,希望各位大神指教,谢谢


Could not autowire. No beans of 'AppMessageMapper' type found. less... (Ctrl+F1)
Checks autowiring problems in a bean class.

***************************************************************************************
java.lang.NullPointerException: null
at com.example.mybatis.test.APPMessageController.getAllMessage(APPMessageController.java:30) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]

*************************************************************************
@Component
public class AppMessageService implements IAppMessageService {

@Autowired
private AppMessageMapper appMessageMapper;
...全文
554 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cwmlow 2019-07-02
  • 打赏
  • 举报
回复
看代码 看看controller层@Autowired注解是否装配的是AppMessageService,然后看看dao层的mapper文件有没有加@mapper注解跟mapper.xml做映射
朝霞清辉 2019-07-02
  • 打赏
  • 举报
回复
昨天看错了,不确定是不是那个mapper注入失败。controller第二十行是什么,看报错是这里的问题
「已注销」 2019-07-02
  • 打赏
  • 举报
回复
java.lang.NullPointerException: null at com.example.mybatis.test.APPMessageController.getAllMessage(APPMessageController.java:30) APPMessageController 30行这里有空指针
sfbayscott2008 2019-07-01
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.example.mybatis.test.AppMessageMapper" >

<resultMap id="BaseResultMap" type="com.example.mybatis.test.AppMessage" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="message" property="message" jdbcType="VARCHAR" />
<result column="senddate" property="senddate" jdbcType="TIMESTAMP" />
</resultMap>

<sql id="Base_Column_List" >
id, message, senddate
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from appuser_message
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from appuser_message
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.example.mybatis.test.AppMessage" >
insert into appuser_message (id, message, senddate
)
values (#{id,jdbcType=VARCHAR}, #{message,jdbcType=VARCHAR}, #{senddate,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" parameterType="com.example.mybatis.test.AppMessage" >
insert into appuser_message
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="message != null" >
message,
</if>
<if test="senddate != null" >
senddate,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=VARCHAR},
</if>
<if test="message != null" >
#{message,jdbcType=VARCHAR},
</if>
<if test="senddate != null" >
#{senddate,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.example.mybatis.test.AppMessage" >
update appuser_message
<set >
<if test="message != null" >
message = #{message,jdbcType=VARCHAR},
</if>
<if test="senddate != null" >
senddate = #{senddate,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.example.mybatis.test.AppMessage" >
update appuser_message
set message = #{message,jdbcType=VARCHAR},
senddate = #{senddate,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=VARCHAR}
</update>

<select id="selectAll" resultMap="BaseResultMap">
select
id, message, senddate
from appuser_message
order by senddate asc
</select>

<select id="getMessById" resultMap="BaseResultMap" parameterType="java.lang.String">
select
id, message, senddate
from
appuser_message
where id = #{id,jdbcType=VARCHAR}
order by senddate asc
</select>

</mapper>
sfbayscott2008 2019-07-01
  • 打赏
  • 举报
回复

#mysql
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

#mybatis
mybatis.mapper-locations=classpath:/mappers/*Mapper.xml
mybatis.type-aliases-package=com.example.mybatis.test
朝霞清辉 2019-07-01
  • 打赏
  • 举报
回复
AppMessageMapper这个没找到啊,你是怎么配置这个mapper的,检查一下吧
tongqing9205 2019-07-01
  • 打赏
  • 举报
回复
你是不是应该在Controller里面注入mapper啊

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧