- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个批处理项目,正在尝试部署到 Tomcat 6.0 服务器。我使用 Maven 作为我的构建管理工具,并且项目构建没有错误。但是,一旦我尝试部署,就会收到以下错误:
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retrieveKeys': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.company.obc.idle.dao.PnetDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
这是我的 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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<import resource="applicationContext-sql.xml"/>
<import resource="applicationContext-db.xml" />
<!-- <import resource="applicationContext-mq.xml" /> -->
<context:component-scan base-package="com.company.app.obc.idle" />
<!-- NEEDED FOR JAXB TO WORK -->
<mvc:annotation-driven />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
<bean id="retrieveKeys" class="com.company.obc.idle.batch.RetrieveKeys" />
<bean id="jobProcessUnmarkedPTOEventKeysDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="retrieveKeys" />
<property name="targetMethod" value="retrieveKeys" />
<property name="concurrent" value="false" />
</bean>
<bean id="cronTriggerProcessUnmarkedPTOEventKeys" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobProcessUnmarkedPTOEventKeysDetail" />
<!-- TEST -->
<property name="cronExpression" value="0/15 * * * * ?" />
<!-- PROD
<property name="cronExpression" value="0 30 1/6 * * ?" /> -->
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTriggerProcessUnmarkedPTOEventKeys" />
</list>
</property>
</bean>
这是我尝试使用 quartz 计时器调用的 RetrieveKeys 类。我尝试了许多不同的方法来使其正常工作,并且这个最新版本尝试命名组件以尝试解决问题:
@Component(("retrieveKeys"))
public class RetrieveKeys {
@Resource
PnetDAO PnetDAO;
@Resource
ProcessEvents ProcessEvents;
private static Logger log = Logger.getLogger(RetrieveKeys.class);
public void retrieveKeys() throws Exception{
//SOME MORE CODE
我还将包括我的 DAO 及其实现。我想知道为什么问题中会提到这一点,因为还有另一个以相同方式设置的 DAO 类,但错误中没有提到它。
public interface PnetDAO {
public abstract List<UnprocessedKeys> SelectUnprocessedEvents() throws Exception;
public abstract List<IdleEvent> SelectDetailedEventInformation(String uniqkey) throws Exception;
public abstract int UpdatePTOIdle(int statusFlag, String uniqKey) throws Exception;
}
...
@Repository
public class PnetDAOImpl extends NamedParameterJdbcDaoSupport implements PnetDAO {
private static Logger log = Logger.getLogger(PnetDAOImpl.class);
@Resource(name = "queriesBean")
private Properties sql;
@SuppressWarnings("rawtypes")
private Map<Class, RowMapper> rowMappers;
@Autowired
public PnetDAOImpl(@Qualifier("com.company.datasource.PNETPRD") DataSource ds){
super();
this.setDataSource(ds);
}
//ACCESSING DATA HERE
我很困惑为什么 Spring 会查看我的 DAO,而我没有在 applicationContext 文件中的任何地方提到它。有人有什么想法吗?谢谢!
最佳答案
您告诉 Spring 在 RetrieveKeys 组件中 Autowiring PNetDAO 实例:
@Resource
PnetDAO PnetDAO;
因此 Spring 尝试查找实现此接口(interface)的 bean,但没有找到,因此抛出异常。
它找不到您的实现类,因为它位于 com.company.obc.idle.dao
包中,并且您告诉 Spring 扫描 com.company 包中的类。 app.obc.idle
.
关于java - 无法创建 bean——需要 Autowire 候选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19325642/
这更像是一个最佳实践类型的问题。 我听过很多次: a) 在 Spring 中 Autowiring 时,最佳做法是 Autowiring 接口(interface)“而不是”实现。 和.. b) 我还
我正在查看工作区中的一些旧示例。我看不出怎么样由于没有 @Autowired, Autowiring 完成。 Spring boot + facebook 默认配置。 @Controller @Req
事实似乎并非如此。我曾经认为 XML 配置是为了覆盖注释。但是当我在XML配置中设置autowire =“no”时,bean的@Autowired注释属性仍然有效。我不再确定 XML autowire
为什么需要 Autowiring ? Autowiring 概念的解释是什么?@autowired Spring Framework 中的注释. 最佳答案 不需要 Autowiring ,只是方便。
来自this Spring documentation我知道当我使用@Bean时,默认值已经相当于: @Bean(autowire = Autowire.NO) (Default) No autowi
遇到了一个奇怪的要求。我需要将唯一的错误 ID 附加到 log4j 消息并将该消息 ID 返回给接口(interface)。所以,我虽然让我们创建一个 spring 服务,就像这样 public cl
这个问题已经有答案了: @Autowire failing with @Repository (3 个回答) 已关闭 4 年前。 我有一个类“ReportEverythingForm”,它拒绝通过自动
我是 Spring 的新手。我正面临 Spring-Boot 的问题。我正在尝试将一个字段从外部配置文件 Autowiring 到一个 Autowiring 的 bean 中。我有以下类(class)
我有一个带有存储库的 Spring Boot 应用程序。 我还使用@Service并扩展其中的存储库。 当我尝试 @Autowired 我拥有的服务时: Caused by: org.springfr
我有一个接口(interface)C,想要访问另外两个类中的getClassName()。访问 a.getClassName() 时,method1() 中出现异常。 public interface
我遇到了一个奇怪的问题,其中注入(inject)了 @Autowire 的 Component 在一个类中可用,但在另一个类中不可用。 我在Account和Agreement类的属性network中使
考虑以下示例代码: public class SmallCar { private CarEngine carEngine; @Autowired public SmallCa
autowire = "no"和 autowire = "default"有什么区别?如果它们相同,那么为什么我们有这 2 个选项。 最佳答案 Beans The default is "defaul
我已将项目更改为使用注释而不是 xml 文件,但这会增加应用程序部署时间。现在我正在寻找减少它的方法。 按类型 Autowiring 和按名称 Autowiring 之间有性能差异吗? 热烈欢迎任何其
我有一个与 Web 插件一起使用的 spring boot 应用程序。 在一节课中我有: package com.test.company @Component @RestController pub
我有一个可以执行某些操作的系统。该系统使用以下方法为每个对象创建一个单独的线程: stp.scheduleWithFixedDelay((EditSite) ctx.getBean("EditSite
我正在尝试自动连接存储库,但它无法工作。我已经为此苦苦挣扎了一个星期,但我似乎无法弄清楚。有趣的是,当我注释掉人员存储库的 Autowiring 时,程序可以正常工作并正确编译,但是一旦我尝试 Aut
意味着如果具有所需类型的 bean 不超过 1 个,bean 的所有字段将自动注入(inject)依赖项。 问题是当使用注解时它是如何工作的,它到底能不能工作。 我的测试表明即使我使用 @Resou
我有一个 Autowiring 其他 bean 的组件: @Component public class MyComponent { @Autowired private Enviro
这是我的类代码,其中有 @Autowired 字段: 测试A @ContextConfiguration("classpath:spring.xml") public abstract class T
我是一名优秀的程序员,十分优秀!