File tree Expand file tree Collapse file tree
spring-data-elasticsearch
java/com/baeldung/spring/data/es
test/java/com/baeldung/spring/data/es Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111
1212 <properties >
1313 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
14+ <maven .compiler.source>1.8</maven .compiler.source>
15+ <maven .compiler.target>1.8</maven .compiler.target>
1416
15- <org .springframework.data.version>1.3.2.RELEASE</org .springframework.data.version>
1617 <org .springframework.version>4.2.5.RELEASE</org .springframework.version>
1718
1819 <junit .version>4.11</junit .version>
2728 <artifactId >spring-core</artifactId >
2829 <version >${org.springframework.version} </version >
2930 </dependency >
31+ <dependency >
32+ <groupId >org.springframework.data</groupId >
33+ <artifactId >spring-data-elasticsearch</artifactId >
34+ <version >${elasticsearch.version} </version >
35+ </dependency >
36+
3037 <dependency >
3138 <groupId >junit</groupId >
3239 <artifactId >junit-dep</artifactId >
3946 <version >${org.springframework.version} </version >
4047 <scope >test</scope >
4148 </dependency >
42- <dependency >
43- <groupId >org.springframework.data</groupId >
44- <artifactId >spring-data-elasticsearch</artifactId >
45- <version >${elasticsearch.version} </version >
46- </dependency >
47- <dependency > <groupId >net.java.dev.jna</groupId >
49+ <dependency >
50+ <groupId >net.java.dev.jna</groupId >
4851 <artifactId >jna</artifactId >
4952 <version >4.1.0</version >
5053 <scope >test</scope >
5154 </dependency >
55+
5256 <dependency >
5357 <groupId >org.slf4j</groupId >
5458 <artifactId >slf4j-api</artifactId >
8185 <version >1.2.13</version >
8286 </dependency >
8387 </dependencies >
84- <build >
85- <plugins >
86- <plugin >
87- <artifactId >maven-compiler-plugin</artifactId >
88- <version >2.3.2</version >
89- <configuration >
90- <source >1.8</source >
91- <target >1.8</target >
92- </configuration >
93- </plugin >
94- </plugins >
95- </build >
96- </project >
88+
89+ </project >
Original file line number Diff line number Diff line change @@ -32,18 +32,22 @@ public class Config {
3232 public Client client () {
3333 try {
3434 final Path tmpDir = Files .createTempDirectory (Paths .get (System .getProperty ("java.io.tmpdir" )), "elasticsearch_data" );
35-
35+ logger .debug (tmpDir .toAbsolutePath ().toString ());
36+
3637 // @formatter:off
3738
3839 final Settings .Builder elasticsearchSettings =
3940 Settings .settingsBuilder ().put ("http.enabled" , "false" )
4041 .put ("path.data" , tmpDir .toAbsolutePath ().toString ())
4142 .put ("path.home" , elasticsearchHome );
43+
44+ return new NodeBuilder ()
45+ .local (true )
46+ .settings (elasticsearchSettings )
47+ .node ()
48+ .client ();
49+
4250 // @formatter:on
43-
44- logger .debug (tmpDir .toAbsolutePath ().toString ());
45-
46- return new NodeBuilder ().local (true ).settings (elasticsearchSettings .build ()).node ().client ();
4751 } catch (final IOException ioex ) {
4852 logger .error ("Cannot create temp dir" , ioex );
4953 throw new RuntimeException ();
Original file line number Diff line number Diff line change 1010@ Service
1111public class ArticleServiceImpl implements ArticleService {
1212
13- private ArticleRepository articleRepository ;
14-
13+ private final ArticleRepository articleRepository ;
14+
1515 @ Autowired
16- public void setArticleRepository (ArticleRepository articleRepository ) {
16+ public ArticleServiceImpl (ArticleRepository articleRepository ) {
1717 this .articleRepository = articleRepository ;
1818 }
1919
Original file line number Diff line number Diff line change 88 </appender >
99
1010 <logger name =" org.springframework" level =" WARN" />
11- <logger name =" com.baeldung.config" level =" DEBUG" />
1211
13- <!-- in order to debug some marshalling issues, this needs to be TRACE -->
14- <logger name =" org.springframework.web.servlet.mvc" level =" WARN" />
12+ <!-- in order to debug some elastic issues, this needs to be DEBUG or INFO -->
13+ <logger name =" org.elasticsearch" level =" INFO" />
14+ <logger name =" com.baeldung.spring" level =" DEBUG" />
1515
1616 <root level =" INFO" >
1717 <appender-ref ref =" STDOUT" />
Original file line number Diff line number Diff line change 3434import org .springframework .data .elasticsearch .core .query .SearchQuery ;
3535import org .springframework .test .context .ContextConfiguration ;
3636import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
37- import org .springframework .test .context .support .AnnotationConfigContextLoader ;
3837
3938import com .baeldung .spring .data .es .config .Config ;
4039import com .baeldung .spring .data .es .model .Article ;
4140import com .baeldung .spring .data .es .model .Author ;
4241import com .baeldung .spring .data .es .service .ArticleService ;
4342
4443@ RunWith (SpringJUnit4ClassRunner .class )
45- @ ContextConfiguration (classes = { Config . class }, loader = AnnotationConfigContextLoader .class )
44+ @ ContextConfiguration (classes = Config .class )
4645public class ElasticSearchQueryTest {
4746
4847 @ Autowired
Original file line number Diff line number Diff line change 2121import org .springframework .data .elasticsearch .core .query .SearchQuery ;
2222import org .springframework .test .context .ContextConfiguration ;
2323import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
24- import org .springframework .test .context .support .AnnotationConfigContextLoader ;
2524
2625import com .baeldung .spring .data .es .config .Config ;
2726import com .baeldung .spring .data .es .model .Article ;
2827import com .baeldung .spring .data .es .model .Author ;
2928import com .baeldung .spring .data .es .service .ArticleService ;
3029
3130@ RunWith (SpringJUnit4ClassRunner .class )
32- @ ContextConfiguration (classes = { Config . class }, loader = AnnotationConfigContextLoader .class )
31+ @ ContextConfiguration (classes = Config .class )
3332public class ElasticSearchTest {
3433
3534 @ Autowired
You can’t perform that action at this time.
0 commit comments