spring-data-jpa+spring-data-mongodb 설정 및jar 충돌 이상해
12594 단어 spring-data-jpa
스프링-data-jpa+스프링-data-mongodb를 동시에 집적할 때 리포지토리(DAO)층을 구분하는 데 주의해야 한다
내 방식
모두 *.dao 끝은 모두 Spring data jpa로 간주됨
모두 *.mongo.repository는 모두spring-data-mongodb로 간주됩니다
이유:
레거시 코드 호환
spring-data-mongo.xml 설정
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd"
default-lazy-init="false">
<!-- Default bean name is 'mongo' -->
<!--<mongo:mongo host="192.168.199.78" port="27017" />-->
<bean class="com.mongodb.MongoClient" id="mongo">
<constructor-arg value="192.168.199.78" />
<constructor-arg value="27017" />
</bean>
<mongo:db-factory id="mongoDbFactory" dbname="mongo_qmbiz" mongo-ref="mongo"/>
<!-- by default look for a Mongo object named 'mongo' - default name used for the converter is 'mappingConverter' -->
<mongo:mapping-converter id="mappingConverter" base-package="com.qumei.*.mongodb">
<mongo:custom-converters base-package="com.qumei.*.mongodb.converter">
</mongo:custom-converters>
</mongo:mapping-converter>
<!-- set the mapping converter to be used by the MongoTemplate -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
<constructor-arg name="mongoConverter" ref="mappingConverter"/>
<property name="writeConcern" value="SAFE" />
</bean>
<!-- MongoDB GridFS Template -->
<bean id="gridTemplate" class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
<constructor-arg ref="mongoDbFactory"/>
<constructor-arg ref="mappingConverter"/>
</bean>
<bean class="org.springframework.data.mongodb.core.mapping.event.LoggingEventListener"/>
</beans>
설정할 때 몬고:repositories, 모든 몬godb 패키지의dao를 배제해야 합니다
<!-- Spring Data Mongo -->
<mongo:repositories base-package="com.qumei.**.mongodb.repository" >
<repository:exclude-filter type="regex" expression="com.qumei.core.*" />
</mongo:repositories>
spring-data-jpa 설정
설정할 때 jpa:repositories, 모든mongodb 패키지의dao를 배제해야 합니다
<!-- Spring Data JPA -->
<jpa:repositories base-package="com.qumei.**.dao"
transaction-manager-ref="transactionManager"
entity-manager-factory-ref="entityManagerFactory">
<repository:exclude-filter type="regex" expression="com.qumei.core.*" />
</jpa:repositories>
jpa:repositories mongo:repositories에 대응하는dao 주의 구역을 나누면 서로 다른 결말이나 가방 이름으로 구분하는 것이 좋습니다
실행 중 발견된 문제
예외 로그
17:07:35.900 INFO o.s.b.f.s.DefaultListableBeanFactory[829] - Overriding bean definition for bean 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': replacing [Root bean: class [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
17:07:36.392 ERROR o.s.web.context.ContextLoader[336] - Context initialization failed
java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/FieldNamingStrategy
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.7.0_51]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531) ~[na:1.7.0_51]
at java.lang.Class.getDeclaredMethods(Class.java:1855) ~[na:1.7.0_51]
at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:129) ~[spring-core-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassUtils.isLiteConfigurationCandidate(ConfigurationClassUtils.java:157) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:108) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:278) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:462) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java) ~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4772) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [catalina.jar:8.0.15]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.15]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.15]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.15]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) [catalina.jar:8.0.15]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1585) [catalina.jar:8.0.15]
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source) ~[na:na]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_51]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.15]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:na]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.7.0_51]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463) [catalina.jar:8.0.15]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413) [catalina.jar:8.0.15]
at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source) ~[na:na]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_51]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.15]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:na]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.7.0_51]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487) [na:1.7.0_51]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97) [na:1.7.0_51]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328) [na:1.7.0_51]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420) [na:1.7.0_51]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848) [na:1.7.0_51]
at sun.reflect.GeneratedMethodAccessor105.invoke(Unknown Source) ~[na:na]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_51]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) [na:na]
at sun.rmi.transport.Transport$1.run(Transport.java:177) [na:na]
at sun.rmi.transport.Transport$1.run(Transport.java:174) [na:na]
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_51]
at sun.rmi.transport.Transport.serviceCall(Transport.java:173) [na:na]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556) [na:na]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811) [na:na]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670) [na:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_51]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.model.FieldNamingStrategy
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1295) ~[catalina.jar:8.0.15]
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147) ~[catalina.jar:8.0.15]
... 53 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.model.FieldNamingStrategy
org가 없습니다.springframework.data.mapping.model.FieldNamingStrategy
클래스, 하지만 분명히 마븐에 Spring 관련 의존도가 설정되어 있습니다
해결 방법:
1 유형명 분석에 근거하여 이런 종류가 org에 있음을 알 수 있다.springframework.데이터(spring-data-commons)
2 패키지 컴파일을 생성한lib에 의하면 현재 사용되는jar는spring-data-jpa-1.6.4라는 것을 알 수 있다.RELEASE spring-data-mongodb-1.6.2.RELEASE spring-data-commons-1.8.4.RELEASE(IDEA의 분석도를 통해 이 가방이spring-data-jpa에 의존한다는 것을 알 수 있음)
3spring-data-commons-1.8.4를 보십시오.RELEASE는jar내에 org가 없다는 것을 알게 되었다.springframework.data.mapping.model.FieldNamingStrategy
진입http://mvnrepository.com/spring-data-commons를 검색해서 새로운spring-data-commons-1.9.2를 다운로드하세요.RELEASE
5 충돌 해결
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.9.2.RELEASE</version>
</dependency>
실행, 이상 없음, 오버
수정 및 2015-03-27
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Query By Example을 사용하여 SQL을 작성하지 않고 공백 무시 검색아래와 같이 검색 키워드 입력란이 다수 존재했을 때에, 컨트롤러측에서 if문을 사용해 경우 나누기를 하려고 하면 꽤 힘들게 되고, 코드가 더러워집니다. 거기서 조사한 바, SpringJPA의 「Query By Exa...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.