0

When I use spring-boot-devtools and Spring Security at the same time, the application fails to start. I have been try to exclude UsernamePasswordAuthenticationToken.class in spring-devtools.properties but it doesn't work. So I try to include all JARs about Spring Security. But the question still exists.

My spring-devtools.properties:

restart.include.org.springframework.security=org/springframework/security/authentication/UsernamePasswordAuthenticationToken.class
restart.include.com=com/handchina/yunmart/artemis/config/SecurityConfiguration.class
restart.include.spring-security-core=/spring-security-core-4.2.13.RELEASE.jar
restart.include.spring-security-config=/spring-security-config-4.2.13.RELEASE.jar
restart.include.spring-security-oauth2=/spring-security-oauth2-2.0.18.RELEASE.jar

My pom.xml about devtools and Spring Security.

<spring-cloud.version>Dalston.SR1</spring-cloud.version>
<spring-security.version>4.2.13.RELEASE</spring-security.version>
<spring.version>4.3.30.RELEASE</spring.version>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <version>1.5.22.RELEASE</version>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.0.18.RELEASE</version>
</dependency>

and start logs:

15:57:17.270 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : [/spring-security-oauth2-2.0.18.RELEASE.jar, /spring-security-core-4.2.13.RELEASE.jar, com/handchina/yunmart/artemis/config/SecurityConfiguration.class, org/springframework/security/authentication/UsernamePasswordAuthenticationToken.class, /spring-security-config-4.2.13.RELEASE.jar, /mybatis-plus-[\w-]+.jar]
15:57:17.272 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
15:57:17.275 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Users/hly/IdeaProjects/artemis/target/classes/, file:/C:/Users/hly/.m2/repository/org/springframework/security/spring-security-core/4.2.13.RELEASE/spring-security-core-4.2.13.RELEASE.jar, file:/C:/Users/hly/.m2/repository/org/springframework/security/spring-security-config/4.2.13.RELEASE/spring-security-config-4.2.13.RELEASE.jar, file:/C:/Users/hly/.m2/repository/org/springframework/security/oauth/spring-security-oauth2/2.0.18.RELEASE/spring-security-oauth2-2.0.18.RELEASE.jar]

and the final log i can see

***************************
APPLICATION FAILED TO START
***************************

Description:

Field publisher in com.handchina.yunmart.artemis.config.SecurityConfiguration required a bean of type 'org.springframework.security.authentication.AuthenticationEventPublisher' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationEventPublisher' in your configuration.

Some code in security configuration:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@Profile("!mock")
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Inject
    private UserDetailsService userDetailsService;
    /*-start---------------------------
                Yuvia added,in order to add the wechat authentication provider*/
    @Value("${single-sign.server.host}")
    private String ssourl;
    @Value("${single-sign.server.client-id}")
    private String clientId;
    @Value("${single-sign.server.client-secret}")
    private String clientSecret;
    @Value("${single-sign.server.access-token-uri}")
    private String accessTokenUri;

    @Inject
    private AuthenticationEventPublisher publisher;
dur
  • 15,689
  • 25
  • 79
  • 125

0 Answers0