Приложение Spring Boot: не находит application.properties?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Приложение Spring Boot: не находит application.properties?

Сообщение Anonymous »

У меня есть приложение Spring Boot:
https://github.com/christophstrobl/spri ... 0972a9de72

Он компилируется и отлично работает с: mvn Spring-boot:run

Однако, когда я нажимаю «Запустить как приложение Spring Boot» в Spring Tools Suite, я получаю сообщение о том, что не могу найти ${solr.host}, который настроен в файле application.properties.

Код: Выделить всё

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.data.solr.showcase.product.ProductServiceImpl.setProductRepository(org.springframework.data.solr.showcase.product.ProductRepository); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'solr.host' in string value "${solr.host}"
Мой файл application.properties выглядит следующим образом:

Код: Выделить всё

# SPRING MVC
spring.view.suffix=.jsp
spring.view.prefix=/WEB-INF/views/

# SOLR
solr.host=http://192.168.56.11:8983/solr
Соответствующий класс выглядит так (единственное место, где используется переменная $solr.host). Кроме того, если я напрямую обращаюсь к IP-адресу сервера SOLR (как в прокомментированном коде), приложение запускается нормально.

Код: Выделить всё

* Copyright 2012 - 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.solr.showcase.config;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import org.springframework.data.solr.server.SolrServerFactory;
import org.springframework.data.solr.server.support.MulticoreSolrServerFactory;

/**
* @author Christoph Strobl
*/
@Configuration
@EnableSolrRepositories(basePackages = { "org.springframework.data.solr.showcase.product" })

public class SearchContext {

@Bean
public SolrServer solrServer(@Value("${solr.host}") String solrHost) {
return new HttpSolrServer(solrHost);
}

//  @Bean
//  public SolrServer solrServer(@Value("http://192.168.56.11:8983/solr") String solrHost) {
//      return new HttpSolrServer(solrHost);
//  }

@Bean
public SolrServerFactory solrServerFactory(SolrServer solrServer) {
return new MulticoreSolrServerFactory(solrServer);
}

@Bean
public SolrTemplate solrTemplate(SolrServerFactory solrServerFactory) {
return new SolrTemplate(solrServerFactory);
}

}
Я включаю этот «ProductRepository» — тот, который упоминается в ошибке, — хотя там мало что происходит...

Код: Выделить всё

* Copyright 2012 - 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.solr.showcase.product;

import java.util.Collection;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.query.Query.Operator;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;
import org.springframework.data.solr.showcase.product.model.Product;

/**
* @author Christoph Strobl
*/
interface ProductRepository extends SolrCrudRepository
 {

@Query(fields = { SearchableProductDefinition.ID_FIELD_NAME, SearchableProductDefinition.NAME_FIELD_NAME,
SearchableProductDefinition.PRICE_FIELD_NAME, SearchableProductDefinition.FEATURES_FIELD_NAME,
SearchableProductDefinition.AVAILABLE_FIELD_NAME }, defaultOperator = Operator.AND)
Page findByNameIn(Collection names, Pageable page);

}
У меня есть нечто похожее на «стандартную» файловую структуру... код в src/main/java и так далее. Файл application.properties находится в src/main/resources.

Любые предложения принимаются с благодарностью.

(Быстрый дополнение: Tomcat используется в качестве встроенного сервера)

Подробнее здесь: https://stackoverflow.com/questions/330 ... properties
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»