Spring Boot 1.5.6.RELEASE JpaVendorAdapter无法解析为某种类型

时间:2017-08-09 17:07:09

标签: spring-boot spring-data spring-data-jpa

我使用的是Spring的版本 1.5.4.RELEASE 并且应用程序正常编译,但是当我升级到版本 1.5.6.RELEASE 时,应用程序没有编译了,我找了类和接口的参考,但我在这个版本中没有找到任何关于它的内容,有人可以帮助我吗?

的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

1 个答案:

答案 0 :(得分:1)

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

您可以使用

清除存储库

mvn dependency:purge-local-repository或者只是导航到.m2目录并清除存储库

使用maven插件有一些优点,比如能够传递参数,或忽略传递依赖等。

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