使用Mongo DB启动程序时Spring Boot Gradle依赖冲突

时间:2015-03-10 06:30:49

标签: spring-boot spring-data spring-data-mongodb

以下是我的build.gradle依赖项,

dependencies {

    compile 'org.codehaus.groovy:groovy-all:2.3.7'

    //Spring Boot dependency
    compile "org.springframework.boot:spring-boot-starter-web:1.0.2.RELEASE"
    compile "org.springframework.boot:spring-boot:1.0.2.RELEASE"
    providedRuntime "org.springframework.boot:spring-boot-starter- 
 tomcat:1.0.2.RELEASE"
    compile "org.springframework.boot:spring-boot-starter- 
 jdbc:1.0.2.RELEASE"

    //Embedded Tomcat core plugin
    providedRuntime "org.apache.tomcat.embed:tomcat-embed-core:7.0.52"
    compile "org.apache.tomcat:tomcat-jdbc:7.0.52"

    //Spring jdbc connector
    compile "org.springframework:spring-jdbc:3.2.7.RELEASE"
    compile fileTree('lib')

    testCompile("junit:junit")

    compile(group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2')
    compile(group: 'commons-discovery', name: 'commons-discovery', version: '0.2')
    compile(group: 'commons-logging', name: 'commons-logging', version: '1.1.3')
    compile('mysql:mysql-connector-java:5.1.6')
    compile("org.springframework.boot:spring-boot-starter-data-mongodb")

}

我正在尝试在已使用MySQL驱动程序运行Restful服务的项目中构建基于MongoDB的restful服务。以下是我得到的例外情况。

例外:

2015-03-10 01:26:44.914 ERROR 936 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration#mbeanExporter due to internal class not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:51)
    at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:194)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:148)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
    at org.springframework.boot.SpringApplication$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at com.hack.whereru.Application.main(Application.groovy:25)
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/view/groovy/GroovyMarkupViewResolver
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
    at java.lang.Class.getDeclaredMethods(Class.java:1860)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:571)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:490)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:474)
    at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:534)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:677)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:621)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
    at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:257)
    at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanType(BeanTypeRegistry.java:246)
    at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:227)
    at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:158)
    at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:147)
    at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:119)
    at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:94)
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)
    ... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 40 common frames omitted

我的主要课程:

package com.hack.whereru

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.web.SpringBootServletInitializer
import org.springframework.context.annotation.Configuration
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.ComponentScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer
import org.springframework.context.annotation.Configuration
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.ComponentScan;

@Configuration
@EnableAutoConfiguration
@ComponentScan('com.hack.whereru')

class Application extends SpringBootServletInitializer{

    static void main(String[] args) {

        ApplicationContext ctx = SpringApplication.run(Application.class, args)
        //this.log.info('Starting up SpringBoot application')
        ctx.beanDefinitionNames.sort { it }.each {
            //this.log.info(it)
        }

    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

更新:

当我将我的依赖关系更新到下面时它起作用了。但请好好解释一下原因。

依赖项{

    compile 'org.codehaus.groovy:groovy-all:2.3.7'

    //Spring Boot dependency
    compile "org.springframework.boot:spring-boot-starter-web"

    compile("org.springframework.boot:spring-boot-starter-data-mongodb")

    compile('mysql:mysql-connector-java:5.1.6')

    compile "org.apache.tomcat:tomcat-jdbc:7.0.52"

}

0 个答案:

没有答案