Spring Data JPA 智能在 Intellij 中不起作用

Spring Data JPA intelligence not working in Intellij

我已经使用 Spring Data JPA 设置了一个 spring 启动项目,但我没有看到 Spring data jpa 的智能。

屏幕截图显示了问题,我的 Restaurant 实体有一个变量调用 restaurantAddress,我试图让 intelliJ 帮助我完成编码,但没有智能显示。

我的项目设置如下:

申请class:

@SpringBootApplication
@ComponentScan(basePackages = {"com.mycompany"})
public class Application {

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

POM:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>food</artifactId>
    <version>1.0-SNAPSHOT</version>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <!-- Dependencies for RESTful Web Services -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Dependencies for JPA Data Persistence -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!--JDBC-->
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901-1.jdbc4</version>
        </dependency>

    </dependencies>


    <build>
        <finalName>food</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

</project>

我在我的 IntelliJ 15 上安装了 Spring 数据插件,项目设置:

我通过添加 JavaEE Persistence 框架支持解决了这个问题。只需右键单击项目 select Add Framework Support,然后向下滚动找到 JavaEE Persistence,然后启用复选框并点击确定:

添加 JavaEE 持久性方面

它会添加一个persistence.xml文件,你可以删除它。您的自动补全终于回来了:

关键时刻

更新 您还可以在 Project Structure 中启用 JPA 方面。首先,按 Ctrl Alt Shift S 或转到 Files > Project Structure。点击 Add 按钮并在菜单中,然后 select JPA:

添加 JPA Facet

最后击中 OK