猿问

用于在映射 Informatica PowerCenter 中写入缺失值的 Java 代码

我想测试一个简单关闭应用程序的类:


@Component

public class ShutdownManager {

    @Autowired

    private ApplicationContext applicationcontext;


    public int shutdown(int returnCode) {

        return SpringApplication.exit(applicationcontext, () -> returnCode);

    }

}

我创建的测试用例是这样的:


public class ShutdownManagerTest {

    @Test

    public void should_shutdown_gracefully() {

        SpringApplication app = new SpringApplication(TestClass.class);

        ConfigurableApplicationContext context = app.run();


        ShutdownManager shutdownManager = (ShutdownManager)context.getBean("shutdownManager");


        int result = shutdownManager.shutdown(10);


        assertThat(result).isEqualTo(10);

    }


    @SpringBootApplication

    @ImportResource("classpath:/core/shutdownmanagertest.xml")

    private static class TestClass {

        public TestClass() {

        }


        public static void main(String[] args) {

        }

    }

}

我的 shutdownmanagertest.xml 只包含一个 bean:


<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <bean id="shutdownManager" class="com.mycodebase.ShutdownManager" />


</beans>

但是,当我运行它时,它会抱怨:


Field myOtherService in com.mycodebase.MyTask required a bean of type 'com.mycodebase.MyOtherService ' that could not be found.

MyTask 类位于 ShutdownManager 的同一个包中,其中包含一个字段 myOtherService,该字段具有 @Autowire 注释。但它没有在我的测试 xml 中定义,它只包含一个 bean。


有人可以帮助我理解为什么它会尝试解析不在上下文中的 bean 吗?


爪哇春天弹簧靴


慕勒3428872
浏览 110回答 3
3回答

千万里不及你

您应该在联接器转换中加入两个表。使用 Left(master) outer join 然后将其带入目标。然后将右表中的 BETRG 列映射到目标以及左表中的其余列。发生的情况是,当没有匹配项时,BETRG 将为空。将其放入表达式中,查看该值是否为 null 或空,然后将其更改为 0 或您想要的值。

MMMHUHU

我想测试一个简单关闭应用程序的类:@Componentpublic class ShutdownManager {&nbsp; &nbsp; @Autowired&nbsp; &nbsp; private ApplicationContext applicationcontext;&nbsp; &nbsp; public int shutdown(int returnCode) {&nbsp; &nbsp; &nbsp; &nbsp; return SpringApplication.exit(applicationcontext, () -> returnCode);&nbsp; &nbsp; }}我创建的测试用例是这样的:public class ShutdownManagerTest {&nbsp; &nbsp; @Test&nbsp; &nbsp; public void should_shutdown_gracefully() {&nbsp; &nbsp; &nbsp; &nbsp; SpringApplication app = new SpringApplication(TestClass.class);&nbsp; &nbsp; &nbsp; &nbsp; ConfigurableApplicationContext context = app.run();&nbsp; &nbsp; &nbsp; &nbsp; ShutdownManager shutdownManager = (ShutdownManager)context.getBean("shutdownManager");&nbsp; &nbsp; &nbsp; &nbsp; int result = shutdownManager.shutdown(10);&nbsp; &nbsp; &nbsp; &nbsp; assertThat(result).isEqualTo(10);&nbsp; &nbsp; }&nbsp; &nbsp; @SpringBootApplication&nbsp; &nbsp; @ImportResource("classpath:/core/shutdownmanagertest.xml")&nbsp; &nbsp; private static class TestClass {&nbsp; &nbsp; &nbsp; &nbsp; public TestClass() {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}我的 shutdownmanagertest.xml 只包含一个 bean:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"&nbsp; &nbsp; &nbsp; &nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&nbsp; &nbsp; &nbsp; &nbsp;xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">&nbsp; &nbsp; <bean id="shutdownManager" class="com.mycodebase.ShutdownManager" /></beans>但是,当我运行它时,它会抱怨:Field myOtherService in com.mycodebase.MyTask required a bean of type 'com.mycodebase.MyOtherService ' that could not be found.MyTask 类位于 ShutdownManager 的同一个包中,其中包含一个字段 myOtherService,该字段具有 @Autowire 注释。但它没有在我的测试 xml 中定义,它只包含一个 bean。有人可以帮助我理解为什么它会尝试解析不在上下文中的 bean 吗?爪哇春天弹簧靴

长风秋雁

这是有效的:import java.util.*;private ArrayList<String> myList2 = new ArrayList<String>();QUALF_out = QUALF;BETRG_out = BETRG;SegmentNumber_out = SegmentNumber;DOCNUM = DOCNUM;array_for_search = QUALF + ParentSegmentNumber + DOCNUM ;myList2.add(array_for_search);System.out.println("myList: " + myList2);System.out.println("Array: " + myList2.contains("910" + ParentSegmentNumber + DOCNUM));if(!myList2.contains("910" + ParentSegmentNumber + DOCNUM)){&nbsp; &nbsp; &nbsp; &nbsp; QUALF_out="910";&nbsp; &nbsp; &nbsp; &nbsp; BETRG_out="0";}&nbsp; &nbsp; generateRow();&nbsp;
随时随地看视频慕课网APP

相关分类

Java
我要回答