some minor cleanup (#649)
* minor cleanup pom maven.compiler java versions as properties only specifing spring-data-elasticsearch as dependency formatting net.java.dev.jna dependency grouping main/test and logging dependencies removed unused org.springframework.data.version property * updated logback conf to this example * builder patttern code on multiple lines for readablilty * autowire via constructor into final variable as of spring-4.3 the @Autowired can be omitted \o/ jaj * @ContextConfiguration with less config
This commit is contained in:
parent
db2b93a1b6
commit
6c509ba738
@ -11,8 +11,9 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
<org.springframework.data.version>1.3.2.RELEASE</org.springframework.data.version>
|
||||
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
|
||||
|
||||
<junit.version>4.11</junit.version>
|
||||
@ -27,6 +28,12 @@
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-elasticsearch</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit-dep</artifactId>
|
||||
@ -39,16 +46,13 @@
|
||||
<version>${org.springframework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-elasticsearch</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
</dependency>
|
||||
<dependency> <groupId>net.java.dev.jna</groupId>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
@ -81,16 +85,5 @@
|
||||
<version>1.2.13</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
</project>
|
@ -32,18 +32,22 @@ public class Config {
|
||||
public Client client() {
|
||||
try {
|
||||
final Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data");
|
||||
|
||||
logger.debug(tmpDir.toAbsolutePath().toString());
|
||||
|
||||
// @formatter:off
|
||||
|
||||
final Settings.Builder elasticsearchSettings =
|
||||
Settings.settingsBuilder().put("http.enabled", "false")
|
||||
.put("path.data", tmpDir.toAbsolutePath().toString())
|
||||
.put("path.home", elasticsearchHome);
|
||||
|
||||
return new NodeBuilder()
|
||||
.local(true)
|
||||
.settings(elasticsearchSettings)
|
||||
.node()
|
||||
.client();
|
||||
|
||||
// @formatter:on
|
||||
|
||||
logger.debug(tmpDir.toAbsolutePath().toString());
|
||||
|
||||
return new NodeBuilder().local(true).settings(elasticsearchSettings.build()).node().client();
|
||||
} catch (final IOException ioex) {
|
||||
logger.error("Cannot create temp dir", ioex);
|
||||
throw new RuntimeException();
|
||||
|
@ -10,10 +10,10 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class ArticleServiceImpl implements ArticleService {
|
||||
|
||||
private ArticleRepository articleRepository;
|
||||
|
||||
private final ArticleRepository articleRepository;
|
||||
|
||||
@Autowired
|
||||
public void setArticleRepository(ArticleRepository articleRepository) {
|
||||
public ArticleServiceImpl(ArticleRepository articleRepository) {
|
||||
this.articleRepository = articleRepository;
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework" level="WARN" />
|
||||
<logger name="com.baeldung.config" level="DEBUG" />
|
||||
|
||||
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
|
||||
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
|
||||
<!-- in order to debug some elastic issues, this needs to be DEBUG or INFO -->
|
||||
<logger name="org.elasticsearch" level="INFO" />
|
||||
<logger name="com.baeldung.spring" level="DEBUG" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
|
@ -34,7 +34,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.baeldung.spring.data.es.config.Config;
|
||||
import com.baeldung.spring.data.es.model.Article;
|
||||
@ -42,7 +41,7 @@ import com.baeldung.spring.data.es.model.Author;
|
||||
import com.baeldung.spring.data.es.service.ArticleService;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { Config.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = Config.class)
|
||||
public class ElasticSearchQueryTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -21,7 +21,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.baeldung.spring.data.es.config.Config;
|
||||
import com.baeldung.spring.data.es.model.Article;
|
||||
@ -29,7 +28,7 @@ import com.baeldung.spring.data.es.model.Author;
|
||||
import com.baeldung.spring.data.es.service.ArticleService;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { Config.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = Config.class)
|
||||
public class ElasticSearchTest {
|
||||
|
||||
@Autowired
|
||||
|
Loading…
x
Reference in New Issue
Block a user