Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature/lesson4-quoc #12

Open
wants to merge 1 commit into
base: feature/lesson4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions SpringDI/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>SpringDI</groupId>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chú ý cách đặt groupId với artifactId theo quy tắc nhé, nên để trùng với project gốc

<artifactId>SpringDI</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.13.RELEASE</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package com.trainingdeveloperpro.k001.danghuucanh;
package com.k001.JavaBackEnd.SpringDI;

public class HelloWorld {
private String message;

public HelloWorld(){

public HelloWorld() {
}

public HelloWorld(String message){
this.message = message;
}

public void setMessage(String message) {
public HelloWorld(String message) {
this.message = message;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public void print(){
System.out.println("Print " + this.message);
System.out.println("Print: "+ this.message);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.trainingdeveloperpro.k001.danghuucanh;
package com.k001.JavaBackEnd.SpringDI;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

HelloWorld helloWorld1 = (HelloWorld) context.getBean("helloWorld1");
ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
HelloWorld helloWorld1 = (HelloWorld)context.getBean("helloWorld1");
helloWorld1.print();

HelloWorld helloWorld2 = (HelloWorld) context.getBean("helloWorld2");
HelloWorld helloWorld2 = (HelloWorld)context.getBean("helloWorld2");
helloWorld2.print();
}

}
14 changes: 14 additions & 0 deletions SpringDI/src/main/resources/ApplicationContext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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.0.xsd">

<bean id="helloWorld1" class="com.k001.JavaBackEnd.SpringDI.HelloWorld">
<property name="message" value="inject by setter" />
</bean>

<bean id="helloWorld2" class="com.k001.JavaBackEnd.SpringDI.HelloWorld">
<constructor-arg value="inject by constructor" type="String"></constructor-arg>
</bean>

</beans>
14 changes: 14 additions & 0 deletions SpringDI/target/classes/ApplicationContext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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.0.xsd">

<bean id="helloWorld1" class="com.k001.JavaBackEnd.SpringDI.HelloWorld">
<property name="message" value="inject by setter" />
</bean>

<bean id="helloWorld2" class="com.k001.JavaBackEnd.SpringDI.HelloWorld">
<constructor-arg value="inject by constructor" type="String"></constructor-arg>
</bean>

</beans>
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions src/main/java/com/trainingdeveloperpro/k001/Main.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/resources/beans.xml

This file was deleted.