+spring ioc example
This commit is contained in:
25
Java/spring/ioc/ioc/build.gradle
Normal file
25
Java/spring/ioc/ioc/build.gradle
Normal file
@ -0,0 +1,25 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.1.4'
|
||||
id 'io.spring.dependency-management' version '1.1.3'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
1
Java/spring/ioc/ioc/settings.gradle
Normal file
1
Java/spring/ioc/ioc/settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'ioc'
|
@ -0,0 +1,5 @@
|
||||
@Component
|
||||
public class BeanChild {
|
||||
public int i;
|
||||
public int BeanParent;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = BeanChild.class)
|
||||
public class BeanConfiguration {
|
||||
@Bean
|
||||
public BeanParent getBeanParent() {
|
||||
return new BeanParent(2000);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
public class BeanParent {
|
||||
public int h;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.example.ioc;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class IocApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BeanChild c = new BeanChild();
|
||||
SpringApplication.run(IocApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.example.ioc;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class IocApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user