是什么造成javax.jcr.NoSuchWorkspaceException以及如何修复它

时间:2015-08-31 06:53:39

标签: java

我尝试使用spring4和jackrabbit等开发一些服务器程序。但是,当我使用junit4测试某些类时,会发生javax.jcr.NoSuchWorkspaceException错误。我不知道为什么会发生错误。这个程序昨天运行了!请帮我解决这个问题。

这是测试spring控制器类的测试类。

package kr.ac.jbnu.sql.soremore.controller;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import kr.ac.jbnu.sql.soremore.model.RDML;
import kr.ac.jbnu.sql.soremore.model.Traceability;
import kr.ac.jbnu.sql.soremore.service.RDMLDBException;

import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/config/spring/soremore-servlet.xml" })
public class SoremoreControllerTest {

	@Autowired
	SoremoreController soremoreController = null;

	@Test
	public void storeRDML() {
//		String[] hwpmlPaths = { "resource/sample_rdml/예제 1.xml",
//				"resource/sample_rdml/예제 2.xml",
//				"resource/sample_rdml/예제 3.xml",
//				"resource/sample_rdml/예제 4.xml",
//				"resource/sample_rdml/예제 5.xml",
//				"resource/sample_rdml/예제 6.xml",
//				"resource/sample_rdml/예제 7.xml",
//				"resource/sample_rdml/예제 8.xml",
//				"resource/sample_rdml/예제 9.xml",
//				"resource/sample_rdml/예제 10.xml" };
//
//		for (String hwpmlPath : hwpmlPaths) {
//			soremoreController.storeRDML(hwpmlPath);
//		}
		
		ArrayList<RDML> rdmls = loadTestRDML();
		boolean isSuccessful = false;
		for (RDML rdml : rdmls) {
			try {
				soremoreController.storeRDML(rdml);
				System.out.println();
				isSuccessful = true;
			} catch (Exception e) {
				e.printStackTrace();
				isSuccessful = false;
			}
		}
		Assert.assertTrue(isSuccessful);
	}

	@Test
	public void storeRDMLWithTraceability() throws IOException {
		List<RDML>rdmls = null ;
		String previousRDMLId = "xxx";

		for (RDML rdml : rdmls) {
			soremoreController.storeRDMLWithTraceability(rdml,
					previousRDMLId, TraceabilityTypes.satisfy);
		}
	}

	@Test
	public void updateRDMLWithTraceability() {
		String previousRDMLId1 = "xxx";
		String previousRDMLId2 = "xxx";

		String updatedTraceability = soremoreController.updateRDMLTraceability(
				previousRDMLId1, previousRDMLId2, TraceabilityTypes.satisfy);
	}

	@Test
	public void deleteRDMLWithTraceability() {
		String previousRDMLId1 = "xxx";
		String previousRDMLId2 = "xxx";

		String removedTraceability = soremoreController.deleteRDMLTraceability(
				previousRDMLId1, previousRDMLId2);
	}

	@Test
	public void searchRDML() {
		String rdmlKeyWord = "abc";

		ArrayList<RDML> rdmls = soremoreController.searchRDML(rdmlKeyWord);
		for (RDML rdml : rdmls) {
			System.out.println(rdml);
		}
	}

	@Test
	public void searchRDML0() {
		String rdmlKeyWord = "def";

		ArrayList<RDML> rdmls = soremoreController.searchRDML(rdmlKeyWord);
		for (RDML rdml : rdmls) {
			System.out.println(rdml);
		}
	}

	@Test
	public void searchRDML1() {
		String rdmlKeyWord = "2차년도계획서";

		ArrayList<RDML> rdmls = soremoreController.searchRDML(rdmlKeyWord);
		for (RDML rdml : rdmls) {
			System.out.println(rdml);
		}
	}

	@Test
	public void getRDML() {
		String rdmlID = "abc";
		RDML rdml = soremoreController.getRDML(rdmlID);
	}

	@Test
	public void getParentIDs() {
		String rdmlID = "abcd";

		ArrayList<String> parentIDs = soremoreController.getParentIDs(rdmlID);

		for (String string : parentIDs) {

		}
	}

	@Test
	public void getChildIDs() {
		String rdmlID = "abcd";

		ArrayList<String> childIDs = soremoreController.getChildIDs(rdmlID);

		for (String string : childIDs) {

		}
	}

	public void getDirectLinkedTraceability() {
		String rdmlID = "abcd";
		ArrayList<Traceability> linkedTraceabilities = soremoreController
				.getDirectLinkedTraceability(rdmlID);

		for (Traceability traceability : linkedTraceabilities) {

		}

	}
	
	public ArrayList<RDML> loadTestRDML() {
		ArrayList<RDML> rdmls = new ArrayList<RDML>();
		String xmlSource = "resource/sample_rdml";

		File sourceDir = new File(xmlSource);
		File[] sourceFiles = sourceDir.listFiles();
		for (File file : sourceFiles) {
			RDML rdml = new RDML();
			rdml.setRdmlAsDocument(createDocument(file));
			rdmls.add(rdml);
		}

		return rdmls;
	}

	private Document createDocument(File rdmlPathAsFile) {
		SAXBuilder jdomBuilder = new SAXBuilder();
		Document jdomDocument = null;
		try {
			jdomDocument = jdomBuilder.build(rdmlPathAsFile);
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jdomDocument;
	}
}

这是jackrabbit的repository.xml。

<?xml version="1.0"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->

<!DOCTYPE Repository
          PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.0//EN"
          "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">

<!-- Example Repository Configuration File
     Used by
     - org.apache.jackrabbit.core.config.RepositoryConfigTest.java
     -
-->
<Repository>
    <!--
        virtual file system where the repository stores global state
        (e.g. registered namespaces, custom node types, etc.)
    -->
    <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
        <param name="path" value="${rep.home}/repository"/>
    </FileSystem>

    <!--
        data store configuration
    -->
    <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>

    <!--
        security configuration
    -->
    <Security appName="Jackrabbit">
        <!--
            security manager:
            class: FQN of class implementing the JackrabbitSecurityManager interface
        -->
        <SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security">
            <!--
            workspace access:
            class: FQN of class implementing the WorkspaceAccessManager interface
            -->
            <!-- <WorkspaceAccessManager class="..."/> -->
            <!-- <param name="config" value="${rep.home}/security.xml"/> -->
        </SecurityManager>

        <!--
            access manager:
            class: FQN of class implementing the AccessManager interface
        -->
        <AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager">
            <!-- <param name="config" value="${rep.home}/access.xml"/> -->
        </AccessManager>

        <LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule">
           <!-- 
              anonymous user name ('anonymous' is the default value)
            -->
           <param name="anonymousId" value="anonymous"/>
           <!--
              administrator user id (default value if param is missing is 'admin')
            -->
           <param name="adminId" value="admin"/>
        </LoginModule>
    </Security>

    <!--
        location of workspaces root directory and name of default workspace
    -->
    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
    <!--
        workspace configuration template:
        used to create the initial workspace if there's no workspace yet
    -->
    <Workspace name="${wsp.name}">
        <!--
            virtual file system of the workspace:
            class: FQN of class implementing the FileSystem interface
        -->
        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
            <param name="path" value="${wsp.home}"/>
        </FileSystem>
        <!--
            persistence manager of the workspace:
            class: FQN of class implementing the PersistenceManager interface
        -->
        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
          <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
          <param name="schemaObjectPrefix" value="${wsp.name}_"/>
        </PersistenceManager>
        <!--
            Search index and the file system it uses.
            class: FQN of class implementing the QueryHandler interface
        -->
        <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
            <param name="path" value="${wsp.home}/index"/>
            <param name="supportHighlighting" value="true"/>
        </SearchIndex>
    </Workspace>

    <!--
        Configures the versioning
    -->
    <Versioning rootPath="${rep.home}/version">
        <!--
            Configures the filesystem to use for versioning for the respective
            persistence manager
        -->
        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
            <param name="path" value="${rep.home}/version" />
        </FileSystem>

        <!--
            Configures the persistence manager to be used for persisting version state.
            Please note that the current versioning implementation is based on
            a 'normal' persistence manager, but this could change in future
            implementations.
        -->
        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
          <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
          <param name="schemaObjectPrefix" value="version_"/>
        </PersistenceManager>
    </Versioning>

    <!--
        Search index for content that is shared repository wide
        (/jcr:system tree, contains mainly versions)
    -->
    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
        <param name="path" value="${rep.home}/repository/index"/>
        <param name="supportHighlighting" value="true"/>
    </SearchIndex>

    <!--
        Run with a cluster journal
    -->
    <Cluster id="node1">
        <Journal class="org.apache.jackrabbit.core.journal.MemoryJournal"/>
    </Cluster>
</Repository>

这是soremore-context.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
 
	<context:component-scan base-package="kr.ac.jbnu.sql.soremore" />
 
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
		<property name="contentType" value="text/html; charset=UTF-8" />
	</bean>
	
	<!-- for file upload -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- setting maximum upload size -->
		<property name="maxUploadSize" value="20000000" />

	</bean>
</beans>

这是错误消息。

javax.jcr.NoSuchWorkspaceException: security
	at org.apache.jackrabbit.core.RepositoryImpl.getWorkspaceInfo(RepositoryImpl.java:713)
	at org.apache.jackrabbit.core.RepositoryImpl.markWorkspaceActive(RepositoryImpl.java:931)
	at org.apache.jackrabbit.core.RepositoryImpl.initSecurityManager(RepositoryImpl.java:466)
	at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:332)
	at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:615)
	at org.apache.jackrabbit.core.TransientRepository$3.getRepository(TransientRepository.java:250)
	at org.apache.jackrabbit.core.TransientRepository.startRepository(TransientRepository.java:280)
	at org.apache.jackrabbit.core.TransientRepository.login(TransientRepository.java:376)
	at org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:144)
	at kr.ac.jbnu.sql.soremore.service.rdml.RDMLDBMgmtImpl.<init>(RDMLDBMgmtImpl.java:64)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1088)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1040)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1081)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1006)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:904)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:527)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:260)
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:63)
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:83)
	at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:74)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:116)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:82)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:199)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:251)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:253)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

这是类发生错误的一部分。

@Service
public class RDMLDBMgmtImpl implements IRDMLDBMgmt {
	static Logger logger = Logger.getLogger(SoremoreController.class.getName());
	static private int docNumber = 0;
	private Repository repository;
	private Session session;
	private Node root;
	private Node baseWP = null;
	private Node inputedWP = null;
	private VersionManager vm;
	private QueryManager queryManager;

	public RDMLDBMgmtImpl() throws ParserConfigurationException,
			UnsupportedRepositoryOperationException, RepositoryException {
		super();
		try {
			repository = JcrUtils.getRepository();
			session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
			root = session.getRootNode();
			vm = session.getWorkspace().getVersionManager();
			queryManager = session.getWorkspace().getQueryManager();
		} catch (RepositoryException e) {

			e.printStackTrace();
		}
	}
}

1 个答案:

答案 0 :(得分:0)

您的repository.xml和登录语句中没有任何错误。

尝试从rep.home路径中删除Jackrabbit文件夹,然后重新启动项目,这将创建新的Jackrabbit文件夹。希望这对你有用。

或者您可以尝试:

session = repository.login(新的SimpleCredentials(&#34; admin&#34;,&#34; admin&#34; .toCharArray()),&#34;默认&#34;);