草庐IT

Spring整合JUnit4

全部标签

java - TestNG 和 Spring 3

WhatisthebestpracticewaytodounittestingwithSpring?IassumethecombinationTestNG&jmockitwithSpring3isn'tbad,sothat'swhatI'mdoingrightnow,butifI'moffcourseselectingthetoolsformyfreshSpringproject,pleasetellmerightaway.:-)Anyways,I'vecreatedanentitythatIwanttotest,butI'mnotsurehowtoactuallyruntheTest

java - 为什么 junit4 没有 Assert.assertArrayEquals() for double[]s?

在Junit4中似乎有Assert.assertArrayEquals()方法用于除double之外的所有原语,例如Assert.assertArrayEquals(int[]expected,int[]actual)和Assert.assertArrayEquals(char[]expected,char[]actual)但不是Assert.assertArrayEquals(double[]expected,double[]actual,doubleeps)或Assert.assertArrayEquals(double[]expected,double[]actual,doubl

java - 如何以编程方式使用 Spring 的 JdbcTemplate?

我们使用Spring的JdbcTemplate,它是通过Springconfig进行配置的,如下图所示。有没有办法在不注入(inject)数据源的情况下做到这一点?我只想以编程方式创建JdbcTemplate实例,并使用TheOracleDS“初始化”数据源。我们当前的配置:Java类privateJdbcTemplatejdbcTemplate;@Resource(name="myDataSource")publicvoidsetDataSource(DataSourcedataSource){this.jdbcTemplate=newJdbcTemplate(dataSource)

java - Spring @Transactional 注释不适用于 Autowiring ?

我的应用程序使用SpringAutowiring来配置bean。我刚刚尝试添加@Transactional并且似乎没有调用预期的代理。我希望PersonalController使用事务代理包装的UpdatePublicMapService调用UpdatePublicMapService。我看到的是PersonalController被实例化了两次。第一次它获得代理,但第二次它获得未代理的目标。我做错了什么?非常感谢您的帮助。网络.xml...contextConfigLocation/WEB-INF/applicationContext.xml,/WEB-INF/application

java - Spring Web 服务 - 异常跳过 ExceptionResolver

我有一个SOAP服务,如果我为XML元素指定了错误的输入,请求和响应将按预期工作并具有良好的输入在请求正文中:...asdf...调用了我的异常解析器,这个解析器只是异常解析器的一个实现,所以它没有异常映射,只是抽象方法中的几个System.out但是,如果我发送一个看起来更像这样的请求:...asdf...我的解析器根本没有执行我将log4j设置为具有根调试级别并看到此输出:2010-08-0910:30:01,900[Thread:http-8080-2]DEBUG[org.springframework.ws.transport.http.WebServiceMessageRec

java - 无法让@Rollback 为我的 Spring JPA 集成测试工作

这是我的一个小测试类。问题是它不会在每次测试运行后回滚事务。我做错了什么?:)@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"/META-INF/catalog-spring.xml"})@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)publicclassTermTest{@AutowiredprivateCatalogServiceservice;@Rollba

java - Spring Jndi 配置,Server.xml

我在使用Spring为JNDI设置配置时遇到问题。我检查了其他帖子,但无法解决我的问题。我使用Tomcat6作为我的容器。据我了解,我需要在服务器上设置一个资源。所以在我的server.xml文件中我有这个:我的spring-context.xml中有以下内容(在类路径中):然后我在文件META-INF/context.xml中有这个:我的服务器启动时没有错误。当我尝试运行以下测试时(在我添加JNDI代码之前有效):publicclassTest{publicstaticvoidmain(String[]args){ApplicationContextctx=newClassPathX

java - 从字符串加载 spring 应用程序上下文

谁能告诉我如何使用Spring通过xml字符串而不是文件或类路径资源加载应用程序上下文?谢谢, 最佳答案 使用这个:StringcontextXML=...;Resourceresource=newByteArrayResource(contextXML.getBytes());GenericXmlApplicationContextspringContext=newGenericXmlApplicationContext();springContext.load(resource);ObjectmyBean=springConte

java - JUnit assertEquals 更改字符串

我有一个JUnit测试如下:@TestpublicvoidtestToDatabaseString(){DateConvertorconvertor=newDateConvertor();Datedate=convertor.convert("20/07/1984:00:00:00:00");StringconvertedDate=convertor.toDatabaseString(date);assertEquals("to_date('20/07/1984:00:00:00:00','DD/MM/YYYYHH24:MI:SS')",convertedDate);}测试失败说明:o

java - 我的 pom.xml 中有 javax.inject,spring 会自动使用它吗?

我在网上学习springmvc教程时复制了一个pom.xml,它有:javax.injectjavax.inject1据我所知,spring有自己内置的依赖注入(inject),这会覆盖默认值并使用javax.inject吗?我还在pom中看到了slf4j,没有在代码或xml中进一步设置。这在幕后是如何工作的,spring检查lib的文件夹,如果发现任何可覆盖的lib,它会这样做吗? 最佳答案 你的pom中对javax.inject的依赖javax.injectjavax.inject1与Spring无关。它只是将javax.inj