Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring HelloWorld程序未给出输出_Spring_Maven_Pom.xml - Fatal编程技术网

Spring HelloWorld程序未给出输出

Spring HelloWorld程序未给出输出,spring,maven,pom.xml,Spring,Maven,Pom.xml,这里一切都很好,添加了maven依赖项,但是这个getMsg或getName方法没有给出任何输出 如果我写 ApplicationContext context = new ClassPathXmlApplicationContext("HelloWorldBean.xml"); HelloWorld h1 = (HelloWorld) context.getBean("b1"); h1.getMsg(); h1.getName(); 它将给出msg和name变量的值 这有什么不对吗?在p

这里一切都很好,添加了maven依赖项,但是这个
getMsg
getName
方法没有给出任何输出

如果我写

ApplicationContext context = new ClassPathXmlApplicationContext("HelloWorldBean.xml");
HelloWorld h1 = (HelloWorld) context.getBean("b1");
h1.getMsg(); 
h1.getName(); 
它将给出msg和name变量的值


这有什么不对吗?

在pojo中,getMsg应该有
System.out.println(msg)然后它将打印,否则您必须手动将getMsg方法放入**sysout*中,如图所示。

您能发布HelloWorldBean.xml吗?我看没有什么问题。您似乎混淆了“从方法返回字符串”和“打印字符串”。如果您不理解这一差异,就不应该使用Spring。这就好比你还没学会走路和说话就开波音747一样。
System.out.println(h1.getMsg() + h1.getName()  );