无法配置Spring Mobile Spring 2

时间:2019-05-23 06:02:40

标签: java spring spring-boot spring-mvc spring-mobile

我有一个Spring Boot应用程序,我想从那里开始检测我的设备是移动设备还是浏览器。因此,我认为Spring mobile是个好主意。问题是我无法继续前进。

代码:
根据官方文档here,我实现了以下内容:

public class DeviceConfig implements WebMvcConfigurer{

@Bean
public DeviceResolverHandlerInterceptor 
        deviceResolverHandlerInterceptor() {
    return new DeviceResolverHandlerInterceptor();
}

@Bean
public DeviceHandlerMethodArgumentResolver 
        deviceHandlerMethodArgumentResolver() {
    return new DeviceHandlerMethodArgumentResolver();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(deviceResolverHandlerInterceptor());
}

@Override
public void addArgumentResolvers(
        List<HandlerMethodArgumentResolver> argumentResolvers) {
    argumentResolvers.add(deviceHandlerMethodArgumentResolver());
}


}

以及在我的控制器中

@RequestMapping("/user/mobile")
@PreAuthorize("hasRole('ROLE_USER') and hasRole('ROLE_MOBILE')")
public ModelAndView routeToUserInterfaceServiceMobile(final RedirectAttributes redirectAttrs,Device device) {
    System.out.println(device.isMobile());
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    redirectAttrs.addFlashAttribute("session_userId", userAuthRepository.findByUsername(auth.getName()).getId());
    return new ModelAndView("redirect:"+MyConstants.PATH_USER_MOBILE_SERVICE);

    }

和pom.xml附加内容:

    <dependency>
        <groupId>org.springframework.mobile</groupId>
        <artifactId>spring-mobile-device</artifactId>
        <version>2.0.0.M3</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

问题:
我可以运行该应用程序,但是当我调用此端点时,出现以下错误:

  

找不到接口的主要或默认构造函数   org.springframework.mobile.device.Device   java.lang.IllegalStateException:没有主要或默认构造函数   在以下位置找到了接口org.springframework.mobile.device.Device的设备   org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:219)   在   org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:84)   在   org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:139)   在   org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)   在   org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:165)   在   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)   在

还有其他要添加的内容吗?还是要添加一些弹簧属性?

0 个答案:

没有答案