我RestTemplate在 Spring Boot 2 应用程序中使用 Spring 5,并尝试在其上设置基本 URL/URI,这样我就不必在每个请求前面添加它。这也允许我根据属性设置该值。
以前的版本ReleaseTemplate允许您通过构造函数设置基本 url(例如new ReleaseTemplate(baseUrl))。但现在情况已不再如此。
我看到该类DefaultUriTemplateHandler有一个setBaseUrl()从AbstractUriTemplateHandler接口继承的类,但该类已被弃用。建议的替换类DefaultUriBuilderFactory没有任何此类方法。
任何建议,将不胜感激。谢谢。
我想使用特定的配置文件运行我的 spring-boot 应用程序。因此,我需要将-Dspring.profiles.active=dev参数传递给 JVM。
我的 dockerfile 如下所示:
FROM tomcat:9.0.10-jre8
EXPOSE 8080
ENV JAVA_OPTS="-Dspring.profiles.active=dev"
COPY myapp.war /usr/local/tomcat/webapps/myapp.war
Run Code Online (Sandbox Code Playgroud)
应用程序启动,但带有配置文件名称的 JVM 选项似乎未设置。我缺少什么?
为什么以下基本安全配置不适用于 inMemoryAuthentication() 子句?
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.httpBasic()
.and()
.authorizeRequests()
.anyRequest().authenticated();
super.configure(http);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("username").password("password");
super.configure(auth);
}
}
Run Code Online (Sandbox Code Playgroud)
应用初始化之后,仍然只有userSpring自己生成的default ,没有像username.
我想在重定向后将数据传递到视图。例如,我按下一个按钮,它会将我重定向到包含来自控制器的数据的页面。我正在尝试使用每个人都建议的 RedirectAttribute,但我无法让它工作。任何帮助表示赞赏。
索引.jsp:
<a href="user.htm">Display All Users</a>
Run Code Online (Sandbox Code Playgroud)
控制器:
@RequestMapping(value = "/user.htm")
public ModelAndView addUser(RedirectAttributes redirAtt) {
ModelAndView mv = new ModelAndView("redirect:user");
String out = "All User Details: ";
try {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
List result = session.createQuery("from Users").list();
mv.addObject("users", result);
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
}
redirAtt.addFlashAttribute("message", out);
return mv;
}
Run Code Online (Sandbox Code Playgroud)
我想要在上面显示数据的jsp:user.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${message}</title>
</head>
<body>
<h1>${message}</h1><br>
<table>
<tr>
<th>Username</th>
<th>Nickname</th>
<th>Email</th> …Run Code Online (Sandbox Code Playgroud) 我有一个 Spring Boot MVC + Thymeleaf 应用程序,它通过 Spring Cloud Gateway 与一堆微服务进行通信。
mvc_app -> gateway -> (service_a, service_b,...)
现在,我想实现基于 OAuth 2 的安全性,并且希望将身份验证过程集中在网关级别。
这意味着:
这可以通过以下方式实现:
spring-boot-starter-oauth2-client使用适当的提供者/客户端配置将网关设置为 OAuth 2 客户端问题:
当您通过网关进行身份验证时,身份验证状态将在网关应用程序级别维护。网关成功验证后,如何发回 AccessToken、IdToken 以便mvc_app进一步请求时使用相同的 AccessToken?
java ×4
spring-boot ×4
spring ×3
controller ×1
docker ×1
dockerfile ×1
jsp ×1
oauth-2.0 ×1
spring-mvc ×1
tomcat ×1