问题在于,每次我运行项目时,都会出现org.springframework.beans.factory.UnsatisfiedDependencyException弹出错误。
我已经尝试了一些与答案相关的问题,但是问题尚未解决。
FieldDataService.java
@Component
public interface FieldDataService {
public FieldData getFieldData() throws SQLException, Exception;
}
FieldDataServiceImpl.java
@Component
public class FieldDataServiceImpl implements FieldDataService {
@Autowired
FieldDataDao fieldDataDao;
@Override
public FieldData getFieldData() throws SQLException, Exception {
return this.fieldDataDao.getFieldData();
}
}
FieldDataDao.java
@Component
public interface FieldDataDao {
public FieldData getFieldData() throws SQLException, Exception;
}
FieldDataDaoImpl.java
@Component
public class FieldDataDaoImpl implements FieldDataDao{
@Autowired
private SqlSession sqlSession;
@Override
public FieldData getFieldData() throws SQLException, Exception {
FieldData result = new FieldData();
try {
result = this.sqlSession.selectOne("getFieldData");
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
FieldData.java
@Component
public class FieldData {
private String transactionType;
private String distribution;
private Date startDate;
private Date endDate;
private String reportType;
public String getTransactionType() {
return transactionType;
}
public void setTransactionType(String transactionType) {
this.transactionType = transactionType;
}
public String getDistribution() {
return distribution;
}
public void setDistribution(String distribution) {
this.distribution = distribution;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getReportType() {
return reportType;
}
public void setReportType(String reportType) {
this.reportType = reportType;
}
@Override
public String toString() {
return "FieldData [transactionType=" + transactionType + ", distribution=" + distribution + ", startDate="
+ startDate + ", endDate=" + endDate + ", reportType=" + reportType + "]";
}
}
FieldData.xml
<mapper namespace="com.pnb.allianz.jdt.maper.FieldData">
<resultMap id="FieldDataResultMap" type="FielData">
<result column="LF2S_TRAN_TYPE" property="transactionType"/>
<result column="LF2S_DISTRIBUTION" property="distribution"/>
<result column="LF2S_REPORT_TYPE" property="reportType"/>
</resultMap>
<select id="getFieldData" resultMap="FieldDataResultMap">
SELECT * FROM LF2S_MR_PARAMETERS
WHERE rownum =1
</select>
</mapper>
..并且错误像这样
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'generateJdtController': Unsatisfied dependency expressed through field 'fieldDataService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataServiceImpl': Unsatisfied dependency expressed through field 'fieldDataDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDaoImpl': Unsatisfied dependency expressed through field 'sqlSession'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NullPointerException
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataDao' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\dao\FieldDataDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fieldDataService' defined in file [C:\Users\markanthony.ragay\Desktop\julia-document-tracking\julia-document-tracking\target\classes\com\pnb\allianz\jdt\service\FieldDataService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sqlSessionFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
2019-04-08 14:30:32.380 INFO 2284 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-04-08 14:30:32.410 INFO 2284 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
先谢谢大家。希望你能帮助我。
答案 0 :(得分:0)
您需要检查sqlSessionFactory
。此例外为NullPointerException
。
您的错误消息
通过方法'sqlSessionTemplate'表示的不满意依赖性 参数0;嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 在类路径中创建名称为“ sqlSessionFactory”的bean 资源[ org / mybatis / spring / boot / autoconfigure / MybatisAutoConfiguration.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化[org.apache.ibatis.session.SqlSessionFactory]:工厂 方法'sqlSessionFactory'抛出异常;嵌套异常为 java.lang.NullPointerException