我在Tapesty / Spring中比较新。
我正在尝试为我提交的申请设置测试诉讼。 应用程序正常工作,Tapesty / Spring / Hibernate都很好。
所以我只是创建一个简单的测试
ruamel
└── yaml
├── comments.py
├── compat.py
├── composer.py
├── configobjwalker.py
├── constructor.py
├── cyaml.py
├── dumper.py
├── emitter.py
├── error.py
├── events.py
├── __init__.py
├── loader.py
├── main.py
├── nodes.py
├── parser_.py
├── __pycache__
│ ├── comments.cpython-34.pyc
│ ├── compat.cpython-34.pyc
│ ├── composer.cpython-34.pyc
│ ├── configobjwalker.cpython-34.pyc
│ ├── constructor.cpython-34.pyc
│ ├── cyaml.cpython-34.pyc
│ ├── dumper.cpython-34.pyc
│ ├── emitter.cpython-34.pyc
│ ├── error.cpython-34.pyc
│ ├── events.cpython-34.pyc
│ ├── __init__.cpython-34.pyc
│ ├── loader.cpython-34.pyc
│ ├── main.cpython-34.pyc
│ ├── nodes.cpython-34.pyc
│ ├── parser_.cpython-34.pyc
│ ├── reader.cpython-34.pyc
│ ├── representer.cpython-34.pyc
│ ├── resolver.cpython-34.pyc
│ ├── scalarstring.cpython-34.pyc
│ ├── scanner.cpython-34.pyc
│ ├── serializer.cpython-34.pyc
│ ├── tokens.cpython-34.pyc
│ └── util.cpython-34.pyc
├── reader.py
├── representer.py
├── resolver.py
├── scalarstring.py
├── scanner.py
├── serializer.py
├── tokens.py
└── util.py
ruamel.yaml-0.11.6.dist-info
├── DESCRIPTION.rst
├── INSTALLER
├── METADATA
├── metadata.json
├── namespace_packages.txt
├── RECORD
├── top_level.txt
└── WHEEL
使用以下test-applicationContext.xml
package reservations.services.restaurant;
import java.util.Calendar;
import java.util.Date;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.mytableguru.backend.reservation.service.ReservationService;
import com.mytableguru.backend.restaurant.enums.DayOfTheWeekEnum;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/test-applicationContext.xml" })
public class RestaurantTableAvailabilityServiceImplTest extends AbstractJUnit4SpringContextTests {
@Inject
private ReservationService reservationService;
@Test
public void testContext() {
Assert.assertNotNull(reservationService);
}
}
当我尝试启动测试时,我收到以下错误
<?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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="com.mytableguru" />
<context:property-placeholder location="classpath:database.properties" />
</beans>
我似乎无法弄清楚如何将我的应用程序与JUnit连接,并让它们与Spring等正确连接。
有什么想法吗?
编辑1: 谢谢Lance的输入 我试过以下
Mar 02, 2016 4:07:37 PM org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners
INFO: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4439f31e, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@5dfcfece, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@23ceabc1, org.springframework.test.context.support.DirtiesContextTestExecutionListener@5d5eef3d]
Mar 02, 2016 4:07:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [test-applicationContext.xml]
Mar 02, 2016 4:07:38 PM org.springframework.context.support.GenericApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext@5f341870: startup date [Wed Mar 02 16:07:38 EET 2016]; root of context hierarchy
Mar 02, 2016 4:07:38 PM org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
INFO: Loading properties file from class path resource [database.properties]
Mar 02, 2016 4:07:38 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Mar 02, 2016 4:07:39 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Mar 02, 2016 4:07:39 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
Mar 02, 2016 4:07:39 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kfsx9fffxf5413o5389|71652c98, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.postgresql.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kfsx9fffxf5413o5389|71652c98, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:postgresql://127.0.0.1:5432/reservations, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
INFO 3/2/16 4:07 PM: liquibase: Successfully acquired change log lock
INFO 3/2/16 4:07 PM: liquibase: Reading from public.databasechangelog
INFO 3/2/16 4:07 PM: liquibase: Successfully released change log lock
Mar 02, 2016 4:07:40 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Mar 02, 2016 4:07:40 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.11.Final}
Mar 02, 2016 4:07:40 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.show_sql=false, hibernate.bytecode.use_reflection_optimizer=false, hibernate.format_sql=true, hibernate.use_sql_comments=true}
Mar 02, 2016 4:07:40 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Mar 02, 2016 4:07:40 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL9Dialect
Mar 02, 2016 4:07:40 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Mar 02, 2016 4:07:41 PM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000038: Composite-id class does not override equals(): com.mytableguru.backend.restaurant.model.MenuSection
Mar 02, 2016 4:07:41 PM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000039: Composite-id class does not override hashCode(): com.mytableguru.backend.restaurant.model.MenuSection
Mar 02, 2016 4:07:41 PM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000038: Composite-id class does not override equals(): com.mytableguru.backend.reservation.model.ReservationTable
Mar 02, 2016 4:07:41 PM org.hibernate.mapping.RootClass checkCompositeIdentifier
WARN: HHH000039: Composite-id class does not override hashCode(): com.mytableguru.backend.reservation.model.ReservationTable
Mar 02, 2016 4:07:41 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Mar 02, 2016 4:07:41 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Mar 02, 2016 4:07:42 PM org.springframework.context.support.GenericApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantFileUploadServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mytableguru.backend.restaurant.service.RestaurantService com.mytableguru.backend.restaurant.service.RestaurantFileUploadServiceImpl.restaurantService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.apache.tapestry5.services.AssetSource com.mytableguru.backend.restaurant.service.RestaurantServiceImpl.assetSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.tapestry5.services.AssetSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.apache.tapestry5.ioc.annotations.Inject(), @org.springframework.beans.factory.annotation.Autowired(required=true)}
Mar 02, 2016 4:07:42 PM org.springframework.test.context.TestContextManager prepareTestInstance
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@23ceabc1] to prepare test instance [reservations.services.restaurant.RestaurantTableAvailabilityServiceImplTest@39ab5ef7]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
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)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantFileUploadServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mytableguru.backend.restaurant.service.RestaurantService com.mytableguru.backend.restaurant.service.RestaurantFileUploadServiceImpl.restaurantService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.apache.tapestry5.services.AssetSource com.mytableguru.backend.restaurant.service.RestaurantServiceImpl.assetSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.tapestry5.services.AssetSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.apache.tapestry5.ioc.annotations.Inject(), @org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
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:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mytableguru.backend.restaurant.service.RestaurantService com.mytableguru.backend.restaurant.service.RestaurantFileUploadServiceImpl.restaurantService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.apache.tapestry5.services.AssetSource com.mytableguru.backend.restaurant.service.RestaurantServiceImpl.assetSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.tapestry5.services.AssetSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.apache.tapestry5.ioc.annotations.Inject(), @org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 41 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restaurantServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.apache.tapestry5.services.AssetSource com.mytableguru.backend.restaurant.service.RestaurantServiceImpl.assetSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.tapestry5.services.AssetSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.apache.tapestry5.ioc.annotations.Inject(), @org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 43 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.apache.tapestry5.services.AssetSource com.mytableguru.backend.restaurant.service.RestaurantServiceImpl.assetSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.tapestry5.services.AssetSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.apache.tapestry5.ioc.annotations.Inject(), @org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 54 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.apache.tapestry5.services.AssetSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.apache.tapestry5.ioc.annotations.Inject(), @org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 56 more
但不会传递
@RunWith(TapestryIOCJUnit4ClassRunner.class)
@Registry(modules = { TapestryModule.class, AppModule.class })
public class RestaurantTableAvailabilityServiceImplTest extends AbstractJUnit4SpringContextTests {
@ModuleDef
public static SpringModuleDef createSpringModuleDef() {
final ApplicationContext appContext = new FileSystemXmlApplicationContext("classpath:/test-applicationContext.xml");
ServletContext sc = new MockServletContext();
return new SpringModuleDef(sc) {
@Override
protected ApplicationContext locateApplicationContext(ServletContext servletContext) {
return appContext;
}
};
}
我似乎仍然收到错误
final ApplicationContext appContext = new FileSystemXmlApplicationContext("classpath:/test-applicationContext.xml");
答案 0 :(得分:0)
我认为你需要创建一个SpringModuleDef来模仿TapestrySpringFilter
最简单的方法是使用TapestryIOCJUnit4ClassRunner而不是SpringJUnit4ClassRunner(参见here的例子)
例如:
.box1, .box2, .box3 {
width: 200px;
float:left;
height: 100%;
vertical-align: top;
zoom: 1;
text-align: center;
display: inline-block;
}
答案 1 :(得分:0)
免责声明:我从未使用过tapestry的spring集成。我猜你的代码中某处有一个对ApplicationContextCustomizer的贡献?
文档here说明了
如果您已将Spring配置为允许基于注释的注入, 那么你将能够将Tapestry服务注入你的Spring 豆子。此功能仅在Spring ApplicationContext时可用 未在外部配置和加载。
这是尝试的其他内容:
@RunWith(TapestryIOCJUnit4ClassRunner.class)
@Registry(modules={TapestryModule.class, SpringModule.class, TestModule.class})
public class MyTest {
public static class TestModule {
@Contribute(ApplicationContextCustomizer.class)
public static void addCustomizer(OrderedConfiguration<ApplicationContextCustomizer> config) {
ApplicationContextCustomizer customizer = new ApplicationContextCustomizer() {
public void customizeApplicationContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
applicationContext.setConfigLocation("classpath:/test-applicationContext.xml");
}
};
config.add("mycustomizer", customizer);
}
}
@ModuleDef
public static SpringModuleDef createSpringModuleDef() {
ServletContext sc = new MockServletContext();
return new SpringModuleDef(sc);
}
// @Inject @Test etc