Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 未找到Bean错误_Spring - Fatal编程技术网

Spring 未找到Bean错误

Spring 未找到Bean错误,spring,Spring,下面是代码片段 @Component() public class DbConn { @Resource(name="vDataSource") protected DataSource dataSource; public void doCall () { SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource) // .withCatalogName(config.getPacka

下面是代码片段

@Component()
public class DbConn {

    @Resource(name="vDataSource")
    protected DataSource dataSource;

    public  void doCall () {
    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource)
//          .withCatalogName(config.getPackageName())
            .withProcedureName("TEST_PROC")
            .withoutProcedureColumnMetaDataAccess();
    }
这是我的主课

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/" + "v-test.xml") ;
DbConn d1= context.getBean("dbConn",DbConn.class);
当我尝试运行main时,它会抛出一个错误: 未定义名为“dbConn”的bean

我怎样才能解决这个问题

我的应用程序上下文v-test.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:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
        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.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd">

    <context:annotation-config/>
    <context:property-placeholder/>
    <context:component-scan base-package="com.sgcib.v.conso" />

    <import resource="classpath:spring/v-common-applicationcontext.xml"/>

    <bean id="vltDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.v.driverClassName}"/>
        <property name="url" value="${jdbc.v.url}"/>
        <property name="username" value="${jdbc.v.username}"/>
        <property name="password" value="${jdbc.v.password}"/>
        <property name="testOnBorrow" value="true" />
        <property name="validationQuery" value="SELECT 1 FROM DUAL" />
    </bean>

</beans>

尝试命名您的组件:

@组件(“dbConn”)


你能发布完整的v-test.xml和整个错误吗?问题中添加了。我已经提供了完整的v-test.xml添加了完整的v-test.xml,我修复了这个问题
18:31:31.048 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
18:31:31.078 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@77c2494c]
18:31:31.079 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
18:31:31.081 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dbConn' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:677)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1180)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082)
    at test.MainClass.main(MainClass.java:16)