1

我在我的 spring boot 项目中集成了 LightAdmin 插件,但是运行这个项目会抛出异常。例外是 必须存在至少一个 JPA 元模型。我基本上在 pom.xml 中添加了 springjpa 依赖 spring-boot-starter-data-jpa,但同样的异常抛出。我无法理解,如何解决这些问题请帮助......


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.javabootstar</groupId>
<artifactId>LightAdminExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>LightAdminExample</name>
<description>Spring Boot With LightAdmin</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-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.lightadmin/lightadmin <dependency> 
        <groupId>org.lightadmin</groupId> <artifactId>lightadmin</artifactId> <version>1.0.1.RELEASE</version> 
        </dependency> -->

    <dependency>
        <groupId>org.lightadmin</groupId>
        <artifactId>lightadmin</artifactId>
        <version>1.2.0.RC1</version>
    </dependency>

    <dependency>
        <groupId>org.lightadmin</groupId>
        <artifactId>light-logging-configurer</artifactId>
        <version>1.0.0.RC1</version>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.4.Final</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.2.3.Final</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>compile</scope>
    </dependency>
</dependencies>

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


AppConfig.java


@EnableJpaRepositories(basePackages= {"com.javabootstar.domain"})
@SpringBootApplication

@ComponentScan(basePackages= {"com.javabootstar.administrationConfig"})

@EntityScan(basePackages= {"com.javabootstar.domain"})

public class LightAdminExampleApplication extends SpringBootServletInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    LightAdmin.configure(servletContext)
    .basePackage("org.lightadmin.boot.administration")
    .baseUrl("/admin")
    .security(false)
    .backToSiteUrl("http://lightadmin.org");
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(LightAdminExampleApplication.class);
}

public static void main(String[] args) {
    SpringApplication.run(LightAdminExampleApplication.class, args);
}
}
4

1 回答 1

0

I faced similar issue. I solved it by

  1. Creating new configuration class containing @EnableJpaRepositories & @EntityScan
  2. Remove @EnableJpaRepositories & @EntityScan from root application class
于 2018-05-09T09:00:43.890 回答