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>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<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>
|
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
|
||||||
|
|
||||||
<junit.version>4.11</junit.version>
|
<junit.version>4.11</junit.version>
|
||||||
@ -27,6 +28,12 @@
|
|||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-elasticsearch</artifactId>
|
||||||
|
<version>${elasticsearch.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit-dep</artifactId>
|
<artifactId>junit-dep</artifactId>
|
||||||
@ -39,16 +46,13 @@
|
|||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>net.java.dev.jna</groupId>
|
||||||
<artifactId>spring-data-elasticsearch</artifactId>
|
|
||||||
<version>${elasticsearch.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency> <groupId>net.java.dev.jna</groupId>
|
|
||||||
<artifactId>jna</artifactId>
|
<artifactId>jna</artifactId>
|
||||||
<version>4.1.0</version>
|
<version>4.1.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
@ -81,16 +85,5 @@
|
|||||||
<version>1.2.13</version>
|
<version>1.2.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
|
||||||
<plugins>
|
</project>
|
||||||
<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>
|
|
@ -32,18 +32,22 @@ public class Config {
|
|||||||
public Client client() {
|
public Client client() {
|
||||||
try {
|
try {
|
||||||
final Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data");
|
final Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data");
|
||||||
|
logger.debug(tmpDir.toAbsolutePath().toString());
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
|
|
||||||
final Settings.Builder elasticsearchSettings =
|
final Settings.Builder elasticsearchSettings =
|
||||||
Settings.settingsBuilder().put("http.enabled", "false")
|
Settings.settingsBuilder().put("http.enabled", "false")
|
||||||
.put("path.data", tmpDir.toAbsolutePath().toString())
|
.put("path.data", tmpDir.toAbsolutePath().toString())
|
||||||
.put("path.home", elasticsearchHome);
|
.put("path.home", elasticsearchHome);
|
||||||
|
|
||||||
|
return new NodeBuilder()
|
||||||
|
.local(true)
|
||||||
|
.settings(elasticsearchSettings)
|
||||||
|
.node()
|
||||||
|
.client();
|
||||||
|
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
logger.debug(tmpDir.toAbsolutePath().toString());
|
|
||||||
|
|
||||||
return new NodeBuilder().local(true).settings(elasticsearchSettings.build()).node().client();
|
|
||||||
} catch (final IOException ioex) {
|
} catch (final IOException ioex) {
|
||||||
logger.error("Cannot create temp dir", ioex);
|
logger.error("Cannot create temp dir", ioex);
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
@ -10,10 +10,10 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class ArticleServiceImpl implements ArticleService {
|
public class ArticleServiceImpl implements ArticleService {
|
||||||
|
|
||||||
private ArticleRepository articleRepository;
|
private final ArticleRepository articleRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setArticleRepository(ArticleRepository articleRepository) {
|
public ArticleServiceImpl(ArticleRepository articleRepository) {
|
||||||
this.articleRepository = articleRepository;
|
this.articleRepository = articleRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<logger name="org.springframework" level="WARN" />
|
<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 -->
|
<!-- in order to debug some elastic issues, this needs to be DEBUG or INFO -->
|
||||||
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
|
<logger name="org.elasticsearch" level="INFO" />
|
||||||
|
<logger name="com.baeldung.spring" level="DEBUG" />
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT" />
|
<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.data.elasticsearch.core.query.SearchQuery;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
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.config.Config;
|
||||||
import com.baeldung.spring.data.es.model.Article;
|
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;
|
import com.baeldung.spring.data.es.service.ArticleService;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { Config.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = Config.class)
|
||||||
public class ElasticSearchQueryTest {
|
public class ElasticSearchQueryTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -21,7 +21,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
|
|||||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
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.config.Config;
|
||||||
import com.baeldung.spring.data.es.model.Article;
|
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;
|
import com.baeldung.spring.data.es.service.ArticleService;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { Config.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = Config.class)
|
||||||
public class ElasticSearchTest {
|
public class ElasticSearchTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
Loading…
x
Reference in New Issue
Block a user