Spring数据方面在Intellij 14中不起作用

时间:2015-03-28 08:44:21

标签: java spring jpa intellij-idea spring-data-jpa

现在我正在设置REST api模板。我想使用弹簧数据集成的spring boot,一切都很好,但我想在Intellij 14 spring数据插件中占优势,并在findByFirstName(...)上启用自动完成功能。我尝试在这个intelij 11 demo http://blog.jetbrains.com/idea/2011/11/enjoy-spring-data-jpa-in-intellij-11/

中实现类似的功能

如何在现有项目中启用spring数据插件?

我目前的配置 Intelij settings

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

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories("com.test.repository")
public class TestDataBaseConfiguration {
        @Bean
        public DataSource dataSource() {
            return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
        }

        @Bean
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
            LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
            entityManagerFactoryBean.setDataSource(dataSource());
            entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
            entityManagerFactoryBean.setPackagesToScan("com.test.entities");
            entityManagerFactoryBean.setJpaProperties(jpaProperties());
            return entityManagerFactoryBean;
        }

        private Properties jpaProperties() {
            Properties properties = new Properties();
            properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
            properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
            properties.setProperty("hibernate.show_sql", "false");
            properties.setProperty("hibernate.format_sql", "false");
            return properties;
        }

        @Bean
        public JpaTransactionManager transactionManager() {
            JpaTransactionManager transactionManager = new JpaTransactionManager();
            transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
            transactionManager.setDataSource(dataSource());
            return transactionManager;
        }
}

2 个答案:

答案 0 :(得分:4)

这是一个很大的,https://youtrack.jetbrains.com/issue/IDEA-137023应该用Intellij 15修复

答案 1 :(得分:1)

在我的案例中这是一个愚蠢的问题 - 我错过了启用适当的插件(File - > Settings - > Plugins):

  • 数据库工具和SQL
  • Hibernate支持
  • Java EE:EJB,JPA,Servlets
  • Spring Data