00:49:34.284 [localhost-startStop-1] ERROR o.s.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'puzzleDAOImp': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.mrhunt.dao.PuzzleDAOImp.jdbcTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] 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)}
... 29 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] 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)}
... 31 common frames omitted
和我的web.xml(src/main/webapp/WEB-INF/web.xml)
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>MR.Hunt</display-name>
<servlet>
<servlet-name>main</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
和applicationContext。xml(src/main/webapp/WEB-INF/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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入 -->
<context:component-scan base-package="com.mrhunt.web" />
<context:component-scan base-package="com.mrhunt.model" />
<context:component-scan base-package="com.mrhunt.dao"/>
<context:component-scan base-package="com.mrhunt.service"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClass">
<value>${jdbc.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${jdbc.url}</value>
</property>
<property name="user">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>
<!-- 配置Jdbc模板 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- 配置视图解析器,将ModelAndView及字符串解析为具体的页面 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:viewClass="org.springframework.web.servlet.view.JstlView" p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
最后是. java文件:Puzzle.java(src/main/java/com/mrhunt/Model/Puzzle.java)
package com.mrhunt.model;
import javax.persistence.*;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;
import java.sql.*;
@Entity
@Table(name = "puzzles")
public class Puzzle {
public Puzzle() {
this.pz_id = 10;
this.pz_name = "sin";
}
@Column(name = "pz_id")
private Integer pz_id;
@Column(name = "pz_group")
private String pz_group;
@Column(name = "pz_name")
private String pz_name;
@Column(name = "pz_difficulty")
private Integer pz_difficulty;
@Column(name = "pz_description")
private String pz_description;
@Column(name = "pz_input")
private String pz_input;
@Column(name = "pz_output")
private String pz_output;
@Column(name = "pz_source")
private String pz_source;
@Column(name = "pz_createdate")
@Type(type = "java.sql.Date")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date pz_createdate;
public Integer getPz_id() {
return pz_id;
}
public void setPz_id(Integer pz_id) {
this.pz_id = pz_id;
}
/*And other getter/setter*/
}
java(src/main/java/com/mrhunt/ao)
package com.mrhunt.dao;
import java.util.*;
import com.mrhunt.model.Puzzle;
public interface PuzzleDAO {
public Puzzle getPuzzleByID(int pz_id);
public Map<String, String> getFunctionsByID(int pz_id);
public List<String> getAllGroups();
public Map<Integer, String> getAllPuzzles();
public Map<Integer, String> getPuzzlesByGroup(String pz_group);
}
PuzzleDAOImp.java(src/main/java/com/mrhunt/ao/PuzzleDAOImp.java)
package com.mrhunt.dao;
import java.sql.*;
import java.util.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.jdbc.core.*;
import org.springframework.stereotype.*;
import com.mrhunt.model.Puzzle;
@Repository
public class PuzzleDAOImp implements PuzzleDAO {
@Autowired
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
/*functions are implemented here*/
}
抱歉我的问题太长了。。。如何修复这个错误?
添加
我的类使用@service,而bean已经自动连线,所以我不明白为什么会出现这个错误。
我正在使用java配置而不是XML迁移到spring Security4.0.1。当我自动操作时,它会给出以下错误: HTTP状态500-org.springframework.beans.factory.beanCreationException:创建名为“ScopedTarget.UsersComponent”的bean时出错:注入autowired依赖项失败;嵌套异常为org.springf
我从spring-boot开始,我有一些配置问题。我无法自动操作某些服务。我得到一个BeanCreationException。 Hier是我自动执行服务的控制器: 控制台的错误: 当我从compenentscan中删除两个控制器时,我不会出现这个错误,但我需要扫描这些控制器来访问endpoint。
我试图用Spring DI创建一个简单的HelloWorld应用程序。我创建了一个Java项目并导入了一些教程类,其中一个很简单: 然而,我得到了以下错误:。我正在使用Eclipse Spring Tool Suite 3.7.2,当我单击“修复项目设置”时,我认为通过使用这个Eclipse版本,它会为我添加这些依赖项。我在这里做错了什么?即使在STS中,我也需要手动添加这些依赖项吗?如果是,正确
这是我的当前设置:ProjectRepo: ProjectService: ProjectRestController:
无法连接。无法建立到jdbc的连接:derby://localhost:1527/sample使用组织。阿帕奇。德比。jdbc。ClientDriver(DERBY SQL错误:错误代码:40000,SQLSTATE:XJ040,SQLERRMC:无法使用类加载器sun.misc.Launcher启动数据库'sample'$AppClassLoader@1d44bcfa,有关详细信息,请参见下一个