将javafx客户端与Spring Boot和Spring Security结合使用 [英] using javafx client with spring boot and spring security

查看:90
本文介绍了将javafx客户端与Spring Boot和Spring Security结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用包含身份验证的spring boot创建一个Javafx客户端和http服务器.

I'm going to create a javafx client and http server using spring boot that includes authentication.

服务器正计划使用spring安全性进行登录,并为客户端使用httpClient.

The server is planning to use spring security for login and appache httpClient for clients.

我可以从该结构创建登录服务吗?

Can I create a login service from this structure?

还是应该选择其他方法?

Or should I choose a different method?

我了解Spring安全性使用cookie和会话进行身份验证.

I understand Spring security authenticates using cookie and session.

推荐答案

您可以使用JavaFXSpring-Boot制作混合应用程序.当然,您也可以使用Spring Security.我建议您使用maven项目打包您的混合应用程序.

You can make a hybrid application using JavaFX and Spring-Boot. And of course, you can use Spring Security as well. I recommend you to use maven project to package your hybrid-application.

我可以从该结构创建登录服务吗?

Can I create a login service from this structure?

是的,可以!

还是应该选择其他方法?

Or should I choose a different method?

由于可以将spring-security用于登录服务,因此可能不需要其他方法,但是可以使用很多authentication-authorization库.

As you can use spring-security for your login service, you may not need other methods but you can use a lot of authentication-authorization libraries.

为什么要使用Apache-HttpClient?

似乎您打算使用Apache-HttpClient来绑定JavaFX和Spring-Boot服务.实际上,您可以在JavaFX应用程序中使用登录服务,而无需将该服务公开为Restful Service.您可以使用spring的 Dependency Injection 将服务连接到JavaFX控制器类中.例如:

It seems you are planning to use Apache-HttpClient to bind your JavaFX and Spring-Boot services. Actually you can use your login service in your JavaFX application without exposing the service as a Restful Service. You can use spring's Dependency Injection to wire your service in your JavaFX controller class. ex:

@Autowired
private LoginService loginService;

如果您对spring应用程序感到满意,还可以使用spring提供的功能,例如Spring Data JPA等.

If you are comfortable with spring applications you can also use functionalities that spring provides such as Spring Data JPA, etc.

SpringBoot + JavaFX应用程序

这是混合应用程序的一个简单示例,

Here is a simple example of hybrid application,

import javafx.stage.Stage;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class YourApp extends Application {

    protected ConfigurableApplicationContext springContext;

    public static void main(final String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() throws Exception {
        springContext = springBootApplicationContext();
    }

    @Override
    public void start(Stage stage) throws Exception {
        ....
    }

    @Override
    public void stop() throws Exception {
        springContext.close();
    }

    private ConfigurableApplicationContext springBootApplicationContext() {
        SpringApplicationBuilder builder = new SpringApplicationBuilder(YourApp.class);
        String[] args = getParameters().getRaw().stream().toArray(String[]::new);
        return builder.run(args);
    }

}

不可能在此处定义应用程序的boilerplate,但是上面的代码可以启动应用程序.

It's not possible to define a boilerplate of application here but the above code does the tricks to start the application.

P.S .:您可以检查 JavaFXSpringBootApp 样板,以查看所需的想法.

P.S.: You can check this JavaFXSpringBootApp boilerplate to review the needed ideas.

这篇关于将javafx客户端与Spring Boot和Spring Security结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆