spring boot kotlin错误创建名为'entityManagerFactory'的bean

时间:2018-05-17 13:00:41

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

您好我正在尝试使用kotlin和spring boot构建一个应用程序,同时在docker上运行postgres图像,但我一直收到此错误

@Entity
data class User(
    @Id
    @GeneratedValue
    val id: Long,
    val firstName: String,
    val lastName: String,
    val age:Int,
    val gender:String
    )

.....

这是我的实体

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface UserRepository : JpaRepository<User, Long>

这是我的资料库

@RestController
class UserRestController {


    @Autowired
    lateinit var userRepository: UserRepository

    @RequestMapping(value = "/addUser")
    fun save(): User {

        return userRepository.save(User(id=1,firstName = "chaima",lastName = "ennar",age = 20,gender = "female"))

    }


}

这是我的控制器

server.port=${PORT:9000}
spring.cache.cache-names=googleFeeds,internationalFeeds
spring.cache.caffeine.spec=maximumSize=100,expireAfterAccess=1800s
spring.datasource.url=jdbc:postgresql://localhost:5433/irooldb
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true

这些是我的属性

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
        </dependency>

        <dependency>
            <groupId>com.rometools</groupId>
            <artifactId>rome</artifactId>
            <version>1.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
            <version>2.5.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1206-jdbc42</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

和我的依赖

    <head>
    <!-- Title and Extern files -->
    <title>SSL Checker</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script type="text/javascript" src="js/db.json"></script>
</head>

<body>
    <div id="header">
        <h2>SSL Checker</h2>
    </div>
    <div id="form">
        <p>Introduce the URL:</p>
        <input id="txtbx" type="text">
        <button type="submit" onClick="agregar_caja()">Send</button>
        <div id="inf">
            <p type="text" id="hl1"></p>
            <p type="text" id="hl2"></p>
        </div>
        <script>
            //Extract
            console.log(MyJSON[1].url)
            var cajas = 2
            var boxsaved = MyJSON.length
            fnc = function(info) {
                hey = document.getElementById("hl1").innerHTML = info.url;
            }
            //box creator
            sm = function agregar_caja() {
                document.getElementById("inf").innerHTML += "<p type=text id='hl" + new String(cajas + 1) + "'><br>"
                cajas = cajas + 1
            }
            //Loops
            for (i = 0; i < boxsaved; i++) {
                sm(MyJSON[i]);
            }
            for (i = 0; i < MyJSON.length; i++) {
                fnc(MyJSON[i]);
            }
        </script>
</body>

我的问题是:这个错误意味着什么?我做错了什么?

1 个答案:

答案 0 :(得分:0)

这似乎与此问题重复:java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;

您似乎从运行时类路径中选择了JPA v1 libraty,但是您尝试调用的方法是在JPA v2中定义的