Question

I have an application, but can't get it to run in Eclipse or elsewhere.

Here is my class :

package fr.aaa;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class Computation {

    public Computation() {
    }

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");
        Computation computer = context.getBean(Computation.class);
    }
}

and my applicationContext.xml file :

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:security="http://www.springframework.org/schema/security" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd      
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">  

<import resource="classpath:spring/persistence.xml"/>

<context:annotation-config />
<context:component-scan base-package="fr.aaa.*, com.bbb.*"/> 

<util:properties id="jdbcProps" location="jdbc.properties" />   

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
         <value>classpath:configuration.properties</value>
         <value>classpath:jdbc.properties</value>
        </list>
    </property>
</bean>

I get this exception :

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [fr.aaa.Computation] is defined: expected single bean but found 0:

Am I missing something here ?

Was it helpful?

Solution

Change

fr.aaa.*

to

fr.aaa

Do the same thing for all packages.

The base-package attribute is

The comma-separated list of packages to scan for annotated components.

There are no wildcards involved. You have to use the specific name of the package. Spring will take care of scanning sub packages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top