Spring HelloWorld程序未给出输出
这里一切都很好,添加了maven依赖项,但是这个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
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() );