Spring Security正在初始化,但不验证登录表单数据。

huangapple go评论77阅读模式
英文:

Spring Security is initializing but does not validate the login form data

问题

以下是翻译好的代码部分:

WebSecurityConfig.java

package com.XXX.brxm.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {	
    @Autowired
    private ImplementsUserDetailsService userDetailsSevice;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        System.out.println("HTTP SECURITY!!!");
        http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/css/**", "/js/**", "/img/**", "favicon.ico")
            .permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
    } 			 
	
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        System.out.println("Autenticação!!!");
        auth.userDetailsService(userDetailsSevice).passwordEncoder(new BCryptPasswordEncoder());
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/materialize/**", "/style/**", "/resources/**", "/favicon.ico", "/**");
    }
}

ImplementsUserDetailsService.java

package com.XXX.brxm.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;

import com.XXX.brxm.login.model.Login;
import com.XXX.brxm.login.repository.LoginRepository;

@Repository
public class ImplementsUserDetailsService implements UserDetailsService {

    @Autowired
    private LoginRepository ur;

    @Override
    public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
        Login usuario = ur.findByLogin(login);

        if(usuario == null)
            throw new UsernameNotFoundException("User not found!");

        return usuario;
    }
}

LoginController.java

package com.XXX.brxm.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {

    @RequestMapping(value = "/login")
    public String login() {
        return "login";
    }
}

Login.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>XXX</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&amp;display=swap" rel="stylesheet">
    <meta charset="UTF-8">
</head>
<body>
    <div class="login_main">
        <div class="login-page">
            <img src="/img/logo_grande_fundo_transparente.png" id="logo_form" />
            <div th:fragment="content" class="form">
                <center><strong><legend class="form_text_title">Autenticação</legend></strong></center>
                <br>
                <form name="f" th:action="@{/login}" method="POST" class="login-form">
                    <fieldset class="input_form_fieldset border_form">
                        <legend align="left" class="form_text"> Usuário </legend>
                        <input type="text" id="username" name="username" />
                    </fieldset>
                    <br>
                    <fieldset class="input_form_fieldset border_form">
                        <legend align="left" class="form_text"> Senha </legend>
                        <input type="password" id="password" name="password" />
                    </fieldset>
                    <div class="form-actions">
                        <button type="submit" class="btn border_form">Entrar</button>
                    </div>
                </form>
                <div th:if="${param.error}" class="error">Usuário ou Senha Inválidos.</div>
                <div th:if="${param.logout}" class="alert alert-success">Sessão Encerrada.</div>
                <br>
                <center><p>Copyright &copy; XXX 2020.</p></center>
            </div>
        </div>
    </div>
    <style>
        @media (min-device-width: 700px) {
            /* CSS 样式省略... */
        }
    </style>
    <script>
        $('.message a').click(function() {
            $('form').animate({
                height: "toggle",
                opacity: "toggle"
            }, "slow");
        });
    </script>
</body>
</html>

Main.java

package com.XXX.brxm;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.util.Arrays;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@EnableScheduling
@SpringBootApplication
@EnableResourceServer
public class Main {

    @Autowired
    JobLauncher jobLauncher;

    @Autowired 
    Job transmissionJob;

    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    } 

    @Scheduled(cron = "0 */1 * * * ?")
    public void perform() throws Exception {
        JobParameters params = new JobParametersBuilder()
                .addString("JobID", String.valueOf(System.currentTimeMillis()))
                .toJobParameters();
        jobLauncher.run(transmissionJob, params);
    }
}

请注意,上述翻译可能会涉及到一些代码格式或标点符号的调整,以确保翻译后的代码能够正确运行。如果在实际应用中遇到问题,请逐行检查翻译是否正确。

英文:

I am trying to use Spring Security to authenticate on my Login screen, however any data I type it allows, even blank.

It looks like he's not even triggering the Spring Security module.

In the past this application worked, but the packages were different, after they reorganized the packages, it started to give this problem.

Another test I performed was to remove the code .loginPage ("/ login") and when accessing http: // localhost: 8080 / login error 400 is returned. In my opinion, if the Security module was being called it would return at least error 500, correct?

Can you help me ?

WebSecurityConfig.java

package com.XXX.brxm.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {	
@Autowired
private ImplementsUserDetailsService userDetailsSevice;
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println(&quot;HTTP SECURITY!!!&quot;);
http.csrf().disable()
.authorizeRequests()
.antMatchers(&quot;/css/**&quot;, &quot;/js/**&quot;,&quot;/img/**&quot;, &quot;favicon.ico&quot;)
.permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage(&quot;/login&quot;)
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher(&quot;/logout&quot;))
;
} 			 
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
System.out.println(&quot;Autentica&#231;&#227;o!!!&quot;);
auth.userDetailsService(userDetailsSevice).passwordEncoder(new BCryptPasswordEncoder());
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(&quot;/materialize/**&quot;, &quot;/style/**&quot;, &quot;/resources/**&quot;, &quot;/favicon.ico&quot;, &quot;/**&quot;);
}
}

ImplementsUserDetailsService.java

package com.XXX.brxm.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;
import com.XXX.brxm.login.model.Login;
import com.XXX.brxm.login.repository.LoginRepository;
@Repository
public class ImplementsUserDetailsService implements UserDetailsService{
@Autowired
private LoginRepository ur;
@Override
public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
Login usuario = ur.findByLogin(login);
if(usuario == null)
throw new UsernameNotFoundException(&quot;User not found!&quot;);
return usuario;
}
}

POM.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
&lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;groupId&gt;com.XXX&lt;/groupId&gt;
&lt;artifactId&gt;Publisher&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;name&gt;publisher&lt;/name&gt;
&lt;description&gt;Publisher module for XXX&lt;/description&gt;
&lt;properties&gt;
&lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-batch&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.batch&lt;/groupId&gt;
&lt;artifactId&gt;spring-batch-infrastructure&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.opencsv&lt;/groupId&gt;
&lt;artifactId&gt;opencsv&lt;/artifactId&gt;
&lt;version&gt;4.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-oauth2-client&lt;/artifactId&gt;
&lt;/dependency&gt;                            
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-starter-oauth2&lt;/artifactId&gt;
&lt;version&gt;2.2.4.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.postgresql&lt;/groupId&gt;
&lt;artifactId&gt;postgresql&lt;/artifactId&gt;
&lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.batch&lt;/groupId&gt;
&lt;artifactId&gt;spring-batch-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.validation&lt;/groupId&gt;
&lt;artifactId&gt;validation-api&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
&lt;optional&gt;true&lt;/optional&gt;
&lt;/dependency&gt;
&lt;!-- &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt; 
&lt;/dependency&gt; --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
&lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
&lt;type&gt;jar&lt;/type&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;pluginRepositories&gt;
&lt;pluginRepository&gt;
&lt;id&gt;central&lt;/id&gt;
&lt;name&gt;Central Repository&lt;/name&gt;
&lt;url&gt;https://repo.maven.apache.org/maven2&lt;/url&gt;
&lt;layout&gt;default&lt;/layout&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;releases&gt;
&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
&lt;/releases&gt;
&lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;
&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;central&lt;/id&gt;
&lt;name&gt;Central Repository&lt;/name&gt;
&lt;url&gt;https://repo.maven.apache.org/maven2&lt;/url&gt;
&lt;layout&gt;default&lt;/layout&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;
&lt;/repositories&gt;
&lt;/project&gt;

LoginController.java

package com.XXX.brxm.security;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class LoginController {
@RequestMapping(value = &quot;/login&quot;)
public String login() {
return &quot;login&quot;;
}
}

Login.html

&lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
&lt;head&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;XXX&lt;/title&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Roboto:wght@300&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;login_main&quot;&gt;
&lt;div class=&quot;login-page&quot;&gt;
&lt;img src=&quot;/img/logo_grande_fundo_transparente.png&quot; id=&quot;logo_form&quot; /&gt;
&lt;div th:fragment=&quot;content&quot; class=&quot;form&quot;&gt;
&lt;center&gt;&lt;strong&gt;&lt;legend class=&quot;form_text_title&quot;&gt;Autentica&#231;&#227;o&lt;/legend&gt;&lt;/strong&gt;&lt;/center&gt;
&lt;br&gt;
&lt;form name=&quot;f&quot; th:action=&quot;@{/login}&quot; method=&quot;POST&quot;
class=&quot;login-form&quot;&gt;
&lt;fieldset class=&quot;input_form_fieldset border_form&quot;&gt;
&lt;legend align=&quot;left&quot; class=&quot;form_text&quot;&gt; Usu&#225;rio &lt;/legend&gt;
&lt;input type=&quot;text&quot; id=&quot;username&quot; name=&quot;username&quot; /&gt;
&lt;/fieldset&gt;
&lt;br&gt;
&lt;fieldset class=&quot;input_form_fieldset border_form&quot;&gt;
&lt;legend align=&quot;left&quot; class=&quot;form_text&quot;&gt; Senha &lt;/legend&gt;
&lt;input type=&quot;password&quot; id=&quot;password&quot; name=&quot;password&quot; /&gt;
&lt;/fieldset&gt;
&lt;div class=&quot;form-actions&quot;&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn border_form&quot;&gt;Entrar&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;div th:if=&quot;${param.error}&quot; class=&quot;error&quot;&gt;Usu&#225;rio ou Senha Inv&#225;lidos.&lt;/div&gt;
&lt;div th:if=&quot;${param.logout}&quot; class=&quot;alert alert-success&quot;&gt;Sess&#227;o Encerrada.&lt;/div&gt;
&lt;br&gt;
&lt;center&gt;&lt;p&gt;Copyright &amp;copy; XXX 2020.&lt;/p&gt;&lt;/center&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;style&gt;
@media ( min-device-width : 700px) {
.form_text_title{
color: #01143d;
font-weight: 800;
font-size: 20px;
}
.form_text{
color: #35363a;
font-weight: 800;
font-size: 12px;
}
.error{
color: red;
}
.border_form{
border-radius: 4px;
}
.login_main {
margin: 2% 28%;
}
.form-actions {
padding-top: 10%;
}
.input_form_fieldset {
border-color: #35363a;
padding-inline-start: 1%;
padding-inline-end: 1%;
padding-bottom: 0%;
}
#logo_form {
margin-left: 12%;
width: 250px;
padding-bottom: 14%;
}
.login-page {
width: 360px;
padding: 8% 0 0;
margin: auto;
}
.form {
z-index: 1;
background: #43a04700;
max-width: 360px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0
rgba(0, 0, 0, 0.24);
}
.form input {
font-family: &quot;Roboto&quot;, sans-serif;
outline: 0;
background: #0365a700;
width: 100%;
border: 0;
box-sizing: border-box;
font-size: 14px;
}
::-webkit-input-placeholder {
color: black;
}
.form button {
font-family: &quot;Roboto&quot;, sans-serif;
text-transform: uppercase;
outline: 0;
background: #02123e;
width: 100%;
border: 0;
padding: 9px;
color: #FFFFFF;
font-size: 14px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
}
.form button:hover, .form button:active, .form button:focus {
background: #43A047;
}
.form .message {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 12px;
}
.form .message a {
color: #4CAF50;
text-decoration: none;
}
.form .register-form {
display: none;
}
.container {
position: relative;
z-index: 1;
max-width: 300px;
margin: 0 auto;
}
.container:before, .container:after {
content: &quot;&quot;;
display: block;
clear: both;
}
.container .info {
margin: 50px auto;
text-align: center;
}
.container .info h1 {
margin: 0 0 15px;
padding: 0;
font-size: 36px;
font-weight: 300;
color: #1a1a1a;
}
.container .info span {
color: #4d4d4d;
font-size: 12px;
}
.container .info span a {
color: #000000;
text-decoration: none;
}
.container .info span .fa {
color: #EF3B3A;
}
body {
font-family: &quot;Roboto&quot;, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
}
&lt;/style&gt;
&lt;script&gt;
$(&#39;.message a&#39;).click(function() {
$(&#39;form&#39;).animate({
height : &quot;toggle&quot;,
opacity : &quot;toggle&quot;
}, &quot;slow&quot;);
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

Main.java


package com.XXX.brxm;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.util.Arrays;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@EnableScheduling
@SpringBootApplication
@EnableResourceServer
public class Main {
@Autowired
JobLauncher jobLauncher;
@Autowired 
Job transmissionJob;
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
} 
@Scheduled(cron = &quot;0 */1 * * * ?&quot;)
public void perform() throws Exception {
JobParameters params = new JobParametersBuilder()
.addString(&quot;JobID&quot;, String.valueOf(System.currentTimeMillis()))
.toJobParameters();
jobLauncher.run(transmissionJob, params);
}
}

答案1

得分: 1

只需移除 @EnableResourceServer,我不明白你为什么需要它。

英文:

Just remove @EnableResourceServer, I don't see why you need it.

huangapple
  • 本文由 发表于 2020年9月5日 07:09:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63748938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定