其他分享
首页 > 其他分享> > 我想获得有关Spring BeanCreationException错误的建议

我想获得有关Spring BeanCreationException错误的建议

作者:互联网

这就是之前提出这个问题的人.

问题的错误是成功的,但我遇到了另一个错误.

作为Spring的初学者,有很多我不知道的事情

我有很多问题要问.敬请谅解.

错误代码.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dao.IMemberDAO service.MemberService.memberDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dao.IMemberDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'memberDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\admin\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\rachelivf\WEB-INF\classes\dao\mapper\memberDaoMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'member'.  Cause: java.lang.ClassNotFoundException: Cannot find class: member
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)

以下是MemberService.java代码.

package service;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;


import dao.IMemberDAO;
import model.Member;

@Service
public class MemberService  
{
    @Autowired
    private IMemberDAO memberDao;

    public void joinMember(HashMap<String, Object> params)
    {
        if(params.get("pw").equals(params.get("pwd_CHECK")))
        {
            memberDao.insertMember(params);
        }
    }
}

这是applicationContext.xml代码.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

    <context:component-scan base-package="service" />

    <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
        <property value="com.mysql.jdbc.Driver" name="driverClassName"></property>
        <property value="jdbc:mysql://localhost/rachelvf" name="url"></property>
        <property value="root" name="username"/>
        <property value="mysql" name="password"/>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="mapperLocations" value="classpath*:dao/mapper/*.xml"></property>
    </bean>

    <bean id="memberDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
        <property name="mapperInterface" value="dao.IMemberDAO"></property>
    </bean>

</beans>

我所知道的,

这就是出现上述错误的原因所在

我没有插入注释服务.

但显然我插入了服务注释,但是我收到了一个错误.

请给我建议.

它是memberDaoMapper代码.

<?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="dao.IMemberDAO">
    <insert id="insertMember" parameterType="java.util.HashMap">
        insert into member values
        (
            #{id},#{pw},default     
        )
    </insert>

    <update id="updateMember" parameterType="java.util.HashMap">
        update member set id = #{id}, pw = #{pw}, authority = #{authority}
    </update>

    <delete id="deleteMember" parameterType="String">
        delete from member where id = #{id}
    </delete>

    <select id="selectOne" parameterType="String" resultType="member">
        select * from member where id = #{id}
    </select>

    <select id="selectAll" parameterType="String" resultType="member">
        select * from member
    </select>
</mapper>

它是IMemberDao.java代码.

package dao;

import java.util.HashMap;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;

import model.Member;

public interface IMemberDAO 
{
    public int insertMember(HashMap<String, Object> params);

    public int updateMember(HashMap<String, Object> params);

    public int deleteMember(String id);

    public HashMap<String, Object> selectOne(String id);

    public List<HashMap<String, Object>> selectAll();
}

我彻底检查了错字,但没有找到拼写错误.

有什么问题?

解决方法:

stacktrace的这一部分应该给你一个正确的问题提示:

org.apache.ibatis.type.TypeException: Could not resolve type alias 'member'

如果没有映射器文件,我认为其中一个文件中存在错误,并且您可能在XML属性中编写了成员,该属性需要完全限定的类名.

我的建议是搜索那些文件中的成员,你应该在一个不正确的字段中找到它(大多数像parameterType或resultType)

查看您添加的Mapping文件,您有resultType =“member”.如上所述,resultType需要一个完全限定的类名.
您的问题的解决方案大多是2:

>将resultType修改为实际的类

<select id="selectOne" parameterType="String" resultType="model.Member">
    select * from member where id = #{id}
</select>

<select id="selectAll" parameterType="String" resultType="model.Member">
    select * from member
</select>

>为sampleVO类添加类型别名标记.

<mapper namespace="model.Member">
     <typeAlias alias="member" type="model.Member" />
    ...
</mapper>

标签:dependency-injection,spring-mvc,spring,spring-bean
来源: https://codeday.me/bug/20190705/1390772.html