package com.example.demo.configuration;
import com.example.demo.pojo.Role;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Myconfiguration {
@Bean
public String msg(){
return "this";
}
@Bean
public Role myRole(){
return new Role();
}
}
package com.example.demo.pojo;
import org.springframework.stereotype.Component;
@Component
public class Role {
private String name;
private String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "Role{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
'}';
}
}
package com.example.demo.controller;
import com.example.demo.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyConfigurationController {
@Autowired
private String msg;
@Autowired
private Role role;
@GetMapping("/test")
public String test(){
return msg;
}
@GetMapping("/role")
public String getRole(){
return role.toString();
}
}