why eclipse shows me this error and he can not find a class?

advertisements

i develop with maven spring hibernate and eclipse, i try to insert data to my postgres base data but i have this error

log4j:WARN No appenders could be found for logger  (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main"   org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'a' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1108)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
at com.App.main(App.java:19)

i don't understand this error because every thing is sample and logic this my configurate file 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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.2.xsd">

       <context:component-scan base-package="java.com" />
       <context:annotation-config />

       <tx:annotation-driven transaction-manager="transactionManager"/>
       <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean> 

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:postgresql://localhost:5432/webservices" />
    <property name="username" value="postgres" />
    <property name="password" value="1234" />
</bean>
    <bean id="sessionFactory"    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="java.com" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>
</beans>

this my service

@Service("a")
public class Ws_security_services implements Interface_ws_security_services {

@Autowired
private Interface_ws_security_DAO interface_ws_security_DAO; 

@Transactional
public void addws(Ws_security ws_security) {

    interface_ws_security_DAO.addws(ws_security);
}

and this my class main

package com;

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

 import com.entity.Ws_security;
 import com.services.Interface_ws_security_services;

 public class App {

public static void main(String[] args) {

    @SuppressWarnings("resource")
    ApplicationContext ctx1 = new ClassPathXmlApplicationContext("spring_hibernate.xml");

    Interface_ws_security_services service=(Interface_ws_security_services)    ctx1.getBean("a");

    Ws_security ess=new Ws_security();
    ess.setIDws("ess1");
    ess.setLogin("ess2");
    service.addws(ess);
    System.out.println("Done");

}

    }

please what is my problem and if any one find a solution please write it


You configured your context with

<context:component-scan base-package="java.com" />

And the classes are in the package com:

package com;

Fix the context configuration, and choose a beter package name, respecting the conventions:

package com.mydomainname.myapplication