Vấn đề về spring MVC

Chả là mình đang bắt phải học làm web(để còn đi thi tin học trẻ) nên mình dùng Spring MVC(Vì đã thành thạo vs java). Lúc mình làm chương trình đầu tiên thì bị xảy ra lỗi như sau:

MainApp.java

package springtutorial;

import org.springframework.context.*;
import org.springframework.context.support.*;
public class MainApp 
{
    public static void main(String[] args)
    {
        ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
        HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
    }
}

HelloWorld.java

package springtutorial;

public class HelloWorld 
{
    private String message = "Hello World!";
    
    public void setMessage(String message)
    {
        this.message = message;
    }
    
    public void getMessage(String message)
    {
        System.out.println("Your Message: " + message);
    }
}

Beans.xml

<?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-3.1.xsd">
    
    <bean id="helloWorld" class="springtutorial.HelloWorld">
        <property name="message" value="Hello World!"></property> 
    </bean>
</beans>

Mà khi run nó ra 4 dòng lỗi ngớ ngẩn này(Dù build successful nhưng không chạy là thế nào???).

Mar 02, 2018 6:25:08 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@377dca04: startup date [Fri Mar 02 18:25:08 ICT 2018]; root of context hierarchy
Mar 02, 2018 6:25:08 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
BUILD SUCCESSFUL (total time: 0 seconds)

Bạn nào giỏi về Spring thì giúp mình nhé!!!

Chạy ngon lành rồi em. Vì em không in cái gì nên nó vậy thôi

Gọi tiếp:
obj.getMessage(“Aragami”);

2 Likes

Nó thông báo load bean thôi.
Mà em không gọi hàm getMessage(String message) lấy gì in ra màn hình???

2 Likes

anh @alway5dotcom@drgnz ơi! Close bài này hộ em nhé. Em giải được rồi

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?