Sunday, 15 April 2012

java - Unable to add the dependency of Spring-data into Spring boot -



java - Unable to add the dependency of Spring-data into Spring boot -

i trying start spring boot guide , , manually include dependency of spring-data.

my ide eclipse, , take utilize gradle build project.

both build.gradle , pom.xml has been modified, eclipse still find cannot libraries of spring-data (such org.springframework.data.*) during compile.

below build.gradle , pom.xml.

could suggest go wrong? thanks!!

build.gradle

buildscript { repositories { maven { url "http://repo.spring.io/libs-release" } mavenlocal() mavencentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.1.release") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'war' war { basename = 'xiwami' version = '0.1.0' } jar { basename = 'xiwami' version = '0.1.0' } repositories { mavenlocal() mavencentral() maven { url "http://repo.spring.io/libs-release" } maven { url "http://m2.neo4j.org" } } dependencies { compile("org.springframework.boot:spring-boot-starter-web") // spring info : mongodb compile("org.springframework.data:spring-data-mongodb") // tag::actuator[] compile("org.springframework.boot:spring-boot-starter-actuator") // end::actuator[] testcompile("junit:junit") } task wrapper(type: wrapper) { gradleversion = '1.11' }

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.adarp</groupid> <artifactid>xiwami</artifactid> <version>0.1.0</version> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.1.1.release</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <!-- tag::actuator[] --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-actuator</artifactid> </dependency> <!-- end::actuator[] --> <dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-mongodb</artifactid> </dependency> </dependencies> <properties> <start-class>hello.application</start-class> </properties> <build> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>2.3.2</version> </plugin> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>

there no need manually add together spring info dependencies. spring boot provides starter well. add together

compile("org.springframework.boot:spring-boot-starter-data-jpa") compile("org.springframework.boot:spring-boot-starter-data-mongodb")

to build.gradle

or

<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-mongodb</artifactid> </dependency>

to pom.xml spring info jpa , mongodb support.

the starter contains transitive dependencies need work spring info jpa or mongo.

check out this , this guide.

as mentioned in comments, after changing dependencies don't forget refresh project in ide

java spring gradle spring-data spring-boot

No comments:

Post a Comment