powered by simpleCommunicator - 2.0.49     © 2025 Programmizd 02
Форумы / Java [игнор отключен] [закрыт для гостей] / PropertySource & conversionService
1 сообщений из 1, страница 1 из 1
PropertySource & conversionService
    #39804726
IgoX
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Всем привет
Пробую изучить spring
Хочу прочитать properties и возникает проблема в конвертации данных.
spring-mvc.xml
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
<mvc:annotation-driven conversion-service="conversionService">
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="objectMapper" ref="objectMapper"/>
            </bean>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/plain;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean" id="conversionService">
        <property name="formatters">
            <set>
                <bean class="ru.igorole.voting.web.converter.DateTimeFormatters.LocalDateFormatter"/>
            </set>
        </property>
        <property name="converters">
            <list>
                <bean class="ru.igorole.voting.web.converter.DateTimeFormatters.LocalTimeConverter"/>
            </list>
        </property>
    </bean>
<context:component-scan base-package="ru.igorole.**.service"/>



Код: java
1.
2.
3.
4.
5.
6.
public static class LocalTimeConverter implements Converter<String, LocalTime> {
        @Override
        public LocalTime convert(String source) {
            return StringUtils.isEmpty(source) ? null : LocalTime.parse(source);
        }
    }



Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
@Configuration
@PropertySource("classpath:ini.properties")
public class Properties {
    @Value("${maxTimeForVoting}")
    private LocalTime maxTimeForVoting;

    public LocalTime getMaxTimeForVoting() {
        return maxTimeForVoting;
    }
}


Ошибка
Cannot convert value of type 'java.lang.String' to required type 'java.time.LocalTime': no matching editors or conversion strategy found
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
Можно ли как то прописать что бы @Value нашел класс конвертер?
Спасибо
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / PropertySource & conversionService
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]