2017-08-09 61 views
0

我使用的版本春天启动的1.5.4.RELEASE和应用程序正常编译,但是当我升级到版本1.5.6.RELEASE应用程序不再编译了,我查找了类和接口的引用,但是在这个版本中我没有找到任何有关它的信息,任何人都可以帮助我吗?春季启动1.5.6.RELEASE JpaVendorAdapter不能被解析为一个类型

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<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>com.example</groupId> 
    <artifactId>demo</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>demo</name> 
    <description>Demo project for Spring Boot</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.4.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 


</project> 

PersistenceJPAConfig.java:

package com.example.demo; 

import java.util.Properties; 

import javax.persistence.EntityManagerFactory; 
import javax.sql.DataSource; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.beans.factory.annotation.Value; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.EnableAspectJAutoProxy; 
import org.springframework.context.annotation.PropertySource; 
import org.springframework.context.annotation.PropertySources; 
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; 
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 
import org.springframework.orm.jpa.JpaTransactionManager; 
import org.springframework.orm.jpa.JpaVendorAdapter; 
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; 
import org.springframework.transaction.PlatformTransactionManager; 
import org.springframework.transaction.annotation.EnableTransactionManagement; 

@Configuration 
@ComponentScan(basePackages = { "com.example.demo" }) 
@EnableTransactionManagement 
@PropertySources({ 
     @PropertySource(value = "file:${catalina.home}/webapps/mywebapp.properties", ignoreResourceNotFound = false) }) 
@EnableAspectJAutoProxy 
@EnableJpaRepositories("com.example.demo") 
public class PersistenceJPAConfig { 

    @Value("${driverClassName}") 
    private String driverClassName; 
    @Value("${url}") 
    private String url; 
    @Value("${userDataBase}") 
    private String userDataBase; 
    @Value("${password}") 
    private String password; 
    @Value("${hibernate.dialect}") 
    private String hibernatedialect; 
    @Value("${show_sql:false}") 
    private String show_sql; 
    @Value("${validationQuery:select 1 from dual}") 
    private String validationQuery; 

    @Autowired 
    JpaVendorAdapter jpaVendorAdapter; 

    @Bean() 
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 
     LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); 
     em.setDataSource(dataSource()); 
     em.setJpaVendorAdapter(jpaVendorAdapter); 
     em.setPersistenceUnitName("MyWebApp"); 
     em.setPackagesToScan(new String[] { "com.example.demo" }); 
     em.setJpaProperties(additionalProperties()); 
     em.afterPropertiesSet(); 
     return em; 
    } 

    @Bean 
    public DataSource dataSource() { 

     org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(); 

     dataSource.setDriverClassName(driverClassName); 
     dataSource.setUrl(url); 
     dataSource.setUsername(userDataBase); 
     dataSource.setPassword(password); 
     dataSource.setInitialSize(2); 
     dataSource.setMaxIdle(15); 
     dataSource.setMinIdle(2); 
     dataSource.setRemoveAbandonedTimeout(60 * 60); 
     dataSource.setLogAbandoned(true); 
     dataSource.setTestOnBorrow(true); 
     dataSource.setValidationQuery(validationQuery); 
     dataSource.setTestOnReturn(true); 
     dataSource.setTestWhileIdle(true); 

     return dataSource; 
    } 

    @Bean 
    public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { 
     return new JpaTransactionManager(emf); 
    } 

    @Bean 
    public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { 
     return new PersistenceExceptionTranslationPostProcessor(); 
    } 

    Properties additionalProperties() { 
     Properties properties = new Properties(); 
     properties.setProperty("hibernate.dialect", hibernatedialect); 
     properties.setProperty("hibernate.show_sql", show_sql); 
     properties.setProperty("hibernate.format_sql", "true"); 
     properties.setProperty("hibernate.id.new_generator_mappings", "false"); 
     return properties; 
    } 
} 

错误:

Error

+0

尝试清除本地maven回购,然后更新。 'mvn dependency:purge-local-repository'或者只导航到你的'.m2'目录并清除版本库。 –

+0

这工作完美,把我作为答复批准 – Passella

回答

1

Rea的儿子在更新Spring Boot Parent版本时会发生这种情况,它会更新大量使用的传递依赖项。这些可能无法正确下载并显示导入错误。

您可以清除或者与仓库,

mvn dependency:purge-local-repository或只是导航到你的目录的.m2和擦拭出库

使用Maven插件有喜欢的是可以传递参数,或忽略一些优势传递依赖等。

如果您在Eclipse中打开Maven控制台,或者从CLI运行mvn install,您还可以看到某些情况下jar无法正确下载。它通常会是warn,表明jar有错误的标题或无法读取。

相关问题