Я обновил проект Spring Boot с версии 1.5.3 до 2.0.3.RELEASE. Все отлично работает, когда его развернули на Tomcat.
При развертывании этого приложения на сервере Wildfly возникает следующее исключение:
java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.gr.dm.core.repository.CampaignDetailRepository.getCampaignSummaryByClick(java.util.Date,java.util.Date)! No property click found for type CampaignDetail! Did you mean 'clicks'?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:135)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:184)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Вот код для CampaignDetailRepository.java:
public interface CampaignDetailRepository extends CrudRepository<CampaignDetail, Long> {
@Query(nativeQuery = true)
List<CampaignSummaryDto> getCampaignSummaryByClick(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
И CampaignDetail.java:
@SqlResultSetMapping(name = "CampaignDetail.campaignSummaryMapping", classes ={
@ConstructorResult(targetClass = CampaignSummaryDto.class, columns = {
@ColumnResult(name = "source", type = String.class),
@ColumnResult(name = "cost", type = Double.class),)}) })
@NamedNativeQueries({
@NamedNativeQuery(name = "CampaignDetail.getCampaignSummaryByClick", query = NativeQueries.CAMPAIGN_SUMMARY_BY_CLICK, resultSetMapping = "CampaignDetail.campaignSummaryMapping")})
public class CampaignDetail implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String campaignId;...
Я понимаю, что стратегия поиска по умолчанию в Spring Data JPA CREATE_IF_NOT_FOUND
, но в случае нативного запроса, не должен ли он использовать предоставленный запрос в классе сущностей?
Я не уверен, почему Spring пытается создать запрос по имени метода для метода, аннотированного с помощью nativeQuery = true.
То же приложение прекрасно работает в Tomcat, но выдает исключение при развертывании в Wildfly 9.