在karaf

时间:2016-07-08 15:41:44

标签: java spring spring-mvc karaf

我是Spring的新手,我正在karaf上部署一个测试Web应用程序,该应用程序只发布一个Spring休息服务。在部署期间,我得到以下异常。希望有些人可以帮我弄清问题是什么。感谢

[org.springframework.security.web.access.channel.ChannelProcessingFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 100, Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 200, Root bean: class [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, <restAuthenticationProcessingFilter>, order = 1500, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2000, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 2200, <org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>, order = 2300]
2016-07-08 11:15:56,521 | WARN  | pool-80-thread-3 | XmlWebApplicationContext         | 191 - ASM-InfraMngr-ServerManagement-Module - 0.0.1 | Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Invocation of init method failed; nested exception is java.lang.ClassCastException: org.springframework.web.accept.HeaderContentNegotiationStrategy cannot be cast to org.springframework.web.accept.ContentNegotiationStrategy
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext$3.call(HttpServiceContext.java:338)[109:org.ops4j.pax.web.pax-web-jetty:4.2.2]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext$3.call(HttpServiceContext.java:334)[109:org.ops4j.pax.web.pax-web-jetty:4.2.2]
    at org.ops4j.pax.swissbox.core.ContextClassLoaderUtils.doWithClassLoader(ContextClassLoaderUtils.java:60)[109:org.ops4j.pax.web.pax-web-jetty:4.2.2]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.callContextInitialized(HttpServiceContext.java:333)[109:org.ops4j.pax.web.pax-web-jetty:4.2.2]
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791)[81:org.eclipse.jetty.server:9.2.10.v20150310]
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294)[82:org.eclipse.jetty.servlet:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)[81:org.eclipse.jetty.server:9.2.10.v20150310]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doStart(HttpServiceContext.java:245)[109:org.ops4j.pax.web.pax-web-jetty:4.2.2]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)[84:org.eclipse.jetty.util:9.2.10.v20150310]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl$1.start(JettyServerImpl.java:258)[109:org.ops4j.pax.web.pax-web-jetty:4.2.2]
    at org.ops4j.pax.web.service.internal.HttpServiceStarted.end(HttpServiceStarted.java:1047)[111:org.ops4j.pax.web.pax-web-runtime:4.2.2]
    at org.ops4j.pax.web.service.internal.HttpServiceProxy.end(HttpServiceProxy.java:413)[111:org.ops4j.pax.web.pax-web-runtime:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.RegisterWebAppVisitorWC.end(RegisterWebAppVisitorWC.java:380)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.model.WebApp.accept(WebApp.java:692)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.register(WebAppPublisher.java:237)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:182)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher$WebAppDependencyListener.addingService(WebAppPublisher.java:135)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)[org.osgi.core-6.0.0.jar:]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870)[org.osgi.core-6.0.0.jar:]
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[org.osgi.core-6.0.0.jar:]
    at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[org.osgi.core-6.0.0.jar:]
    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)[org.osgi.core-6.0.0.jar:]
    at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)[org.osgi.core-6.0.0.jar:]
    at org.ops4j.pax.web.extender.war.internal.WebAppPublisher.publish(WebAppPublisher.java:101)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.WebObserver.deploy(WebObserver.java:219)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.WebObserver$1.doStart(WebObserver.java:179)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.extender.SimpleExtension.start(SimpleExtension.java:59)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at org.ops4j.pax.web.extender.war.internal.extender.AbstractExtender$1.run(AbstractExtender.java:280)[107:org.ops4j.pax.web.pax-web-extender-war:4.2.2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_66]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_66]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)[:1.8.0_66]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.8.0_66]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_66]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_66]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_66]
Caused by: java.lang.ClassCastException: org.springframework.web.accept.HeaderContentNegotiationStrategy cannot be cast to org.springframework.web.accept.ContentNegotiationStrategy
    at org.springframework.web.accept.ContentNegotiationManager.<init>(ContentNegotiationManager.java:87)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.web.accept.ContentNegotiationManagerFactoryBean.afterPropertiesSet(ContentNegotiationManagerFactoryBean.java:241)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)[191:ASM-InfraMngr-ServerManagement-Module:0.0.1]
    ... 47 more

Context XML

<context:component-scan base-package="com.asm.infraMngr.serverMngr" />

<mvc:annotation-driven/>


<!-- ================================================================================== -->
<!-- Spring Context Configurationin OSGI scan does not work so define all classes       -->
<!-- ================================================================================== -->

<bean class="com.asm.infraMngr.serverMngr.restController.ServerManagementController"/>


<security:global-method-security secured-annotations="enabled"/>

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- This tag allows for mapping the DispatcherServlet to "/" (all extensions etc)-->
<mvc:default-servlet-handler/>

控制器

@Controller
@Path("/rest")
public class ServerManagementController {


    public ServerManagementController(){
        this.serverMgmtProxyResource = new ServerMgmtProxyResource();
    }



    @RequestMapping( value = "/TestService",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<String> getTestInfo() {

        return new ResponseEntity<String>("Successful Test", HttpStatus.OK);
    }

}

这是我的POM

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Bundle-Name>${project.artifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
                        <Web-ContextPath>asm-services/ServerMngr</Web-ContextPath>
                        <mainClass>com.asm.infraMngr.serverMngr</mainClass>
                        <Import-Package>
                            org.osgi.framework;version=1.0,
                            com.asm.infraMngr.database.services.dao;version=0.0.1,
                            com.asm.infraMngr.database.entity;version=0.0.1,
                            com.asm.infraMngr.net.services;version=0.0.1,
                            org.jvnet.jaxb2_commons.lang;version=0,
                            org.jvnet.jaxb2_commons.locator;version=0,
                            org.apache.log4j.*;version=1.2.15,
                            javax.xml.datatype;version=0.0.0
                        </Import-Package>
                        <Export-Package>list
                        </Export-Package>
                        <DynamicImport-Package>*</DynamicImport-Package>
                    </manifestEntries>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>

</build>

<dependencies>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.osgi</groupId>
        <artifactId>org.osgi.core</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Servlet API -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.asm.infraMngr</groupId>
        <artifactId>ASM-InfraMngr-DataBase-Module</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.asm.infraMngr</groupId>
        <artifactId>ASM-Rest-Security-Module</artifactId>
    </dependency>

    <dependency>
        <groupId>com.asm.infraMngr</groupId>
        <artifactId>ASM-InfraMngr-NetworkCommunication-Module</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Spring Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
    </dependency>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.jvnet.jaxb2_commons</groupId>
        <artifactId>runtime</artifactId>
        <scope>provided</scope>
    </dependency>

</dependencies>

1 个答案:

答案 0 :(得分:0)

我能够纠正这个问题,似乎由于某种未知的原因,我对Idea的项目已被破坏。为了解决这个问题,我使用相同的类和相同的POM创建了一个新项目,安装新的WAR,问题就消失了。