如何将此代码从Spring转换为Spring Boot?

时间:2019-01-24 11:17:34

标签: java spring spring-boot mitreid-connect

我已将MVC MitreID Spring Web应用程序剪切并粘贴到基本的引导Web应用程序中。当我尝试运行它时,我得到:

A component required a bean named 'namedAdmins' that could not be found

代码是:

import org.mitre.openid.connect.client.OIDCAuthenticationFilter;
import org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority;
@RestController
public class HomeController {

private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

@Autowired
private OIDCAuthenticationFilter filter;

@Resource(name = "namedAdmins")
private Set<SubjectIssuerGrantedAuthority> admins;

@RequestMapping(value = "/", method = RequestMethod.GET)

这只是Spring代码,我将@controller更改为@restcontroller。

这在servlet-context.xml中:

<bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider">
    <property name="authoritiesMapper">
        <bean class="org.mitre.openid.connect.client.NamedAdminAuthoritiesMapper">
            <property name="admins" ref="namedAdmins" />
        </bean>
    </property>
</bean>

<util:set id="namedAdmins" value-type="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">

    <bean class="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
        <constructor-arg name="subject" value="90342.ASDFJWFA" />
        <constructor-arg name="issuer" value="http://192.168.1.114:8080/openid-connect-server-webapp/" />
    </bean>
</util:set>

任何人都可以让我开始进行我需要更改的其他事情/寻找可以被识别的bean的位置吗? 这是在我的pom中:

<dependency>
    <groupId>org.mitre</groupId>
    <artifactId>openid-connect-client</artifactId>
    <version>1.3.1</version>
</dependency>

1 个答案:

答案 0 :(得分:2)

您的servlet-context.xml很可能未包含在Spring Boot应用程序中。使用@ImportResource批注导入

@SpringBootApplication
@ImportResource("servlet-context.xml")
public class MyApp {
  // ...
}

或将此XML转换为新的Java配置类,这将是首选方法:

@Configuration
public class MitreConfig {

  @Bean
  public Set<SubjectIssuerGrantedAuthority> namedAdmins() {
    // ...
  }

}