How do I convert this code from Spring to Spring Boot?

schoon :

I have cut and pasted an MVC MitreID Spring web app into a basic boot web app. When I try and run it I get:

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

The code is:

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)

This was just the Spring code with me changing @controller to @restcontroller.

this is in 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>

Can anyone please get me started on what else I need to change/where to look to get the bean recognised? This is in my pom:

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

Most likely your servlet-context.xml is not included in Spring Boot application. Either import it with @ImportResource annotation

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

or convert this XML to a new Java configuration class, which would be the preferred approach:

@Configuration
public class MitreConfig {

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

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=101735&siteId=1