我使用嵌入式tomcat thymeleaf template Engine生成了一个Spring Boot Web应用程序,将包装作为可执行JAR文件。
使用的技术:
弹簧靴1.4.2.Release,弹簧4.3.4.Release,Thymeleaf 2.1.5.Release,Tomcat Embed 8.5.6,Maven 3,Java 8
这是我的安全配置类:
@Configuration
@PropertySource("classpath:/com/tdk/iot/config/app-${APP-KEY}.properties")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${securityConfig.formLogin.loginPage}")
private String loginPage;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage(loginPage)
.defaultSuccessUrl("/books/list")
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/denied")
.and()
.authorizeRequests()
.antMatchers("/mockup/**").permitAll()
.antMatchers("/dinners/**").permitAll()
.antMatchers("/welcome/**").authenticated()
.and()
.logout()
.permitAll()
.logoutSuccessUrl("/index.html");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.passwordEncoder(new StandardPasswordEncoder())
.withUser("test1").password("test1").roles("ADMIN").and()
.withUser("test2").password("test2").roles("USER").and()
.withUser("test3").password("test3").roles("SUPERADMIN");
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertyDefaultConfig() {
return new PropertySourcesPlaceholderConfigurer();
}
}
这是我的登录模板
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
...
</head>
<div class="wrap">
<div class="login">
<div class="logo"><img src="../../../images_pebloc/login.png" width="224" height="71" /></div>
<form th:action="@{/login.html}" method="post">
<p th:if="${loginError}" class="error">Wrong user or password</p>
<div class="input_label"><i class="fa fa-user"></i><input type="text" name="user" placeholder="User" /></div>
<div class="input_label"><i class="fa fa-key"></i><input type="password" name="pass" placeholder="Password" /></div>
</form>
<input type="submit" value="LOGIN" />
<div class="forget">
<a href="#">Do you forgot your password?</a><br/>
<br/>
<span>tdk</span>
</div>
</div>
</div>
但是,当我单击什么都没有发生时,控制台中没有HTML错误,没有JavaScript错误,没有表单错误,没有提交,无论我以表格
您的提交按钮不在form
标签内。将其移入</form>
中,这应该触发您的动作。