Oracle11g 无此定义异常弹簧数据+;JPA&x2B;冬眠

Oracle11g 无此定义异常弹簧数据+;JPA&x2B;冬眠,oracle11g,java-8,spring-data-jpa,c3p0,hibernate-entitymanager,Oracle11g,Java 8,Spring Data Jpa,C3p0,Hibernate Entitymanager,我试图在文档后面做一个Spring数据的示例…但是我在repository接口中得到了一个NoSuchBeanDefinitionException,它似乎没有被代理,也没有包含在Spring容器中…下面是我的示例: 这是我的POM.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=

我试图在文档后面做一个Spring数据的示例…但是我在repository接口中得到了一个NoSuchBeanDefinitionException,它似乎没有被代理,也没有包含在Spring容器中…下面是我的示例:

这是我的POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>mx.com.segal</groupId>
  <artifactId>middleware</artifactId>
  <version>0.01</version>
  <packaging>jar</packaging>
  <name>middleware</name>

  <repositories>
    <repository>
        <id>maven2-repository.dev.java.net</id>
        <name>Java.net Repository for Maven</name>          
        <url>http://download.java.net/maven/2</url>
    </repository>
  </repositories>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    <environment>development</environment>
    <app.main.class>mx.com.segal.front.App</app.main.class>
    <platform>windows</platform>
    <java.version>1.8</java.version>
    <spring.version>4.2.6.RELEASE</spring.version>
    <logger.version>1.1.7</logger.version>
    <logger.facade.version>1.7.21</logger.facade.version>
  </properties>

   <dependencies>
     <dependency>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.1</version>
          <type>maven-plugin</type>
     </dependency>
     <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
     </dependency>
     <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.10.1.RELEASE</version>
     </dependency>
     <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
     </dependency>
     <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.1.Final</version>
     </dependency>
     <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.1.0</version>
     </dependency>
     <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
     </dependency>
     <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>5.1.0.Final</version>
     </dependency>

     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${logger.facade.version}</version>
     </dependency>
     <dependency> 
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logger.version}</version>
     </dependency>
     <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>${logger.version}</version>
     </dependency>
  </dependencies>

  <profiles>
        <profile>
            <id>dev</id>
            <properties>
              <environment>development</environment>
             </properties>
        </profile>      
        <profile>
            <id>pro</id>
            <properties>
              <environment>production</environment>       
            </properties>
        </profile>
    </profiles>

  <build>
     <filters>          
            <filter>
                src/main/discriminators/${platform}_${environment}.properties
            </filter>
     </filters>
     <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>                 
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/*.properties</exclude>
                    <exclude>**/*.xml</exclude>
                </excludes>
            </resource>
     </resources>
     <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.5.1</version>
          <configuration>
               <source>${java.version}</source>
               <target>${java.version}</target>
          </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.1</version>
            <configuration>
               <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <configuration>
              <archive>
                <manifest>
                  <mainClass>${app.main.class}</mainClass>
                </manifest>
              </archive>
            </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
<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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-4.3.xsd">   
    <context:component-scan base-package="mx.com.segal" />          
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>middleware/properties/messages</value>
                <value>default</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>
</beans>
我做错了什么?有什么建议吗CityRepository出现此示例不可用…

已解决

我在middleware.xml中添加了这一行

<import resource="persistence.xml"/>

Resolved,我忘了调用middleware.xml中的persistence.xml,带有
package mx.com.segal.persist.repository.city;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import mx.com.segal.persist.model.Ciudad;

@Repository
public interface CityRepository extends JpaRepository<Ciudad, String>{

    @Query("select c from Ciudad c where c.dsCiudad like :dsCiudad||'%' ")
    List<Ciudad> findByDescripcion(@Param("dsCiudad") String dsCiudad);
}
package mx.com.segal.persist.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "D_CIUDAD")
public class Ciudad implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="ID_D_CIUDAD")
    private String codCiudad;

    @Column(name="DS_CIUDAD")
    private String dsCiudad;

    public Ciudad() {
    }

    public String getCodCiudad() {
        return this.codCiudad;
    }

    public void setCodCiudad(String codCiudad) {
        this.codCiudad = codCiudad;
    }

    public String getDsCiudad() {
        return this.dsCiudad;
    }

    public void setDsCiudad(String dsCiudad) {
        this.dsCiudad = dsCiudad;
    }

}

**This my service pojo:**

package mx.com.segal.persist.service.city.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import mx.com.segal.persist.repository.city.CityRepository;
import mx.com.segal.persist.service.city.ICityService;
import mx.com.segal.persist.model.Ciudad;

@Service
public class CityServiceImpl implements ICityService {

 @Autowired 
 private CityRepository cityRepository;

  public List<Ciudad> getListaCiudades(){ 
      return  (List<Ciudad>)cityRepository.findAll();
  }

  public List<Ciudad> getByDescripcion(String desc){
     return (List<Ciudad>)cityRepository.findByDescripcion(desc);
  }

}
@Component
public class CityManagerImpl implements ICityManager{

    private Logger logger = LoggerFactory.getLogger(this.getClass().getCanonicalName());

    @Autowired
    private ICityService cityServiceImpl;

    @Override
    public List<Ciudad> getCities() {
        logger.debug("Listado de ciudades");
        return cityServiceImpl.getListaCiudades();
    }

    @Override
    public List<Ciudad> getCityByDesc(String desc) {
        logger.debug("Listado de ciudades por descripcion");
        return cityServiceImpl.getByDescripcion(desc);
    }

}
/**
 * Middleware App runner;
 *
 */
public class App 
{
    private static final String[] CONTEXT = new String[] { "context/middleware.xml" };
    private ApplicationContext context;
    private static final Logger logger = LoggerFactory.getLogger("mx.com.segal.front.App");

    public App(){
        context = new ClassPathXmlApplicationContext(CONTEXT);
    }

    public static void main( String... args )
    {

        App p=new App();
        ISimpleManager simple=(ISimpleManager)p.context.getBean("simpleManager");
        ICityManager cityManager=(ICityManager)p.context.getBean("cityManagerImpl");
        List<Ciudad> ciudades=cityManager.getCities();
        for(Ciudad city : ciudades){
            logger.debug("Codigo: "+city.getCodCiudad()+" Descripcion: "+city.getDsCiudad());
        }
    }
}
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cityManagerImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private mx.com.segal.persist.service.city.ICityService mx.com.segal.back.city.impl.CityManagerImpl.cityServiceImpl; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cityServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private mx.com.segal.persist.repository.city.CityRepository mx.com.segal.persist.service.city.impl.CityServiceImpl.cityRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [mx.com.segal.persist.repository.city.CityRepository] 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)}
<import resource="persistence.xml"/>