Компонент с именем mvcHandlerMappingIntrospector типа org.springframework.web.servlet.handler.HandlerMappingIntrospectorJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Компонент с именем mvcHandlerMappingIntrospector типа org.springframework.web.servlet.handler.HandlerMappingIntrospector

Сообщение Anonymous »

Когда я запускаю приложение Spring Boot, я получаю эту ошибку при использовании приведенного ниже кода:

Бин с именем mvcHandlerMappingIntrospector типа org.springframework.web.servlet Для использования MvcRequestMatcher требуется .handler.HandlerMappingIntrospector

Мой pom.xml


4.0.0

org.springframework.boot
spring-boot-starter-parent
3.0.1


com.web
ecommerce
0.0.1-SNAPSHOT
ecommerce
Demo project for Spring Boot

17



org.springframework.boot
spring-boot-starter-actuator



org.springframework.boot
spring-boot-starter-data-jpa


org.springframework.boot
spring-boot-starter-security



org.springframework.boot
spring-boot-starter-thymeleaf


org.springframework.boot
spring-boot-starter-web


org.thymeleaf.extras
thymeleaf-extras-springsecurity6



org.springframework.boot
spring-boot-devtools
runtime
true


org.postgresql
postgresql
runtime


org.springframework.boot
spring-boot-starter-test
test


org.springframework.security
spring-security-test
test


org.projectlombok
lombok
1.18.20
provided



org.springframework.boot
spring-boot-starter-tomcat
provided




org.webjars
bootstrap-datepicker
1.9.0



org.webjars
bootstrap
5.2.3



org.webjars
jquery
3.6.1






org.springframework.boot
spring-boot-maven-plugin






import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {

@Bean
public UserDetailsService userDetailsService() {
return new CustomUserDetailsService();
}

@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService());
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}

@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();

// return new BCryptPasswordEncoder();
}

// @Bean(name = "mvcHandlerMappingIntrospector")
// public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
// return new HandlerMappingIntrospector();
// }

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.cors().disable()
.authorizeHttpRequests()
.requestMatchers("/admin/**").hasRole("ADMIN")
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.usernameParameter("email")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/admin/index")
.permitAll()
.and()
.logout()
.logoutUrl("/admin/logout")
.logoutSuccessUrl("/home");

return http.build();
}
}

Полученная ошибка:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.1)

2023-01-11T15:41:43.510+05:30 INFO 176088 --- [ main] c.alibou.security.SecurityApplication : Starting SecurityApplication using Java 17.0.5 with PID 176088 (C:\Users\guruk\Desktop\springboot 3\spring-boot-3-jwt-security-main\target\classes started by guruk in C:\Users\guruk\Desktop\springboot 3\spring-boot-3-jwt-security-main)
2023-01-11T15:41:43.517+05:30 INFO 176088 --- [ main] c.alibou.security.SecurityApplication : No active profile set, falling back to 1 default profile: "default"
2023-01-11T15:41:44.558+05:30 INFO 176088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-01-11T15:41:44.669+05:30 INFO 176088 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 83 ms. Found 1 JPA repository interfaces.
2023-01-11T15:41:45.162+05:30 INFO 176088 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-01-11T15:41:45.306+05:30 INFO 176088 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.6.Final
2023-01-11T15:41:45.629+05:30 WARN 176088 --- [ main] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
2023-01-11T15:41:45.810+05:30 INFO 176088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-01-11T15:41:46.164+05:30 INFO 176088 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@11b5f4e2
2023-01-11T15:41:46.169+05:30 INFO 176088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-01-11T15:41:46.269+05:30 INFO 176088 --- [ main] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2023-01-11T15:41:47.131+05:30 INFO 176088 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-01-11T15:41:47.154+05:30 INFO 176088 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-01-11T15:41:47.788+05:30 WARN 176088 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Unsatisfied dependency expressed through method 'setFilterChains' parameter 0: Error creating bean with name 'securityFilterChain' defined in class path resource [com/alibou/security/config/SecurityConfiguration.class]: Failed to instantiate [org.springframework.security.web.SecurityFilterChain]: Factory method 'securityFilterChain' threw exception with message: No bean named 'A Bean named mvcHandlerMappingIntrospector of type org.springframework.web.servlet.handler.HandlerMappingIntrospector is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.' available
2023-01-11T15:41:47.792+05:30 INFO 176088 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-01-11T15:41:47.799+05:30 INFO 176088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2023-01-11T15:41:47.805+05:30 INFO 176088 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2023-01-11T15:41:47.831+05:30 INFO 176088 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-01-11T15:41:47.904+05:30 ERROR 176088 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

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

Description:

Parameter 0 of method setFilterChains in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a bean named 'A Bean named mvcHandlerMappingIntrospector of type org.springframework.web.servlet.handler.HandlerMappingIntrospector is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.' that could not be found.

Action:

Consider defining a bean named 'A Bean named mvcHandlerMappingIntrospector of type org.springframework.web.servlet.handler.HandlerMappingIntrospector is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.' in your configuration.

Когда я раскомментирую эту часть:
@Bean(name = "mvcHandlerMappingIntrospector")
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
return new HandlerMappingIntrospector();
}

и запустите приложение. У меня нет ошибок, но приложение автоматически закрывается сразу после запуска:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.1)

2023-01-11T15:53:45.269+05:30 INFO 177140 --- [ restartedMain] com.web.ecommerce.EcommerceApplication : Starting EcommerceApplication using Java 17.0.5 with PID 177140 (C:\Users\guruk\Desktop\springboot 3\ecommerce\target\classes started by guruk in C:\Users\guruk\Desktop\springboot 3\ecommerce)
2023-01-11T15:53:45.277+05:30 INFO 177140 --- [ restartedMain] com.web.ecommerce.EcommerceApplication : No active profile set, falling back to 1 default profile: "default"
2023-01-11T15:53:45.405+05:30 INFO 177140 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-01-11T15:53:45.406+05:30 INFO 177140 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-01-11T15:53:46.684+05:30 INFO 177140 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-01-11T15:53:46.783+05:30 INFO 177140 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 87 ms. Found 1 JPA repository interfaces.
2023-01-11T15:53:47.316+05:30 INFO 177140 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-01-11T15:53:47.404+05:30 INFO 177140 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.6.Final
2023-01-11T15:53:47.685+05:30 WARN 177140 --- [ restartedMain] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
2023-01-11T15:53:47.878+05:30 INFO 177140 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-01-11T15:53:48.292+05:30 INFO 177140 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@1fff2385
2023-01-11T15:53:48.295+05:30 INFO 177140 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-01-11T15:53:48.393+05:30 INFO 177140 --- [ restartedMain] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2023-01-11T15:53:49.209+05:30 INFO 177140 --- [ restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-01-11T15:53:49.223+05:30 INFO 177140 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-01-11T15:53:49.925+05:30 INFO 177140 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@62c9380d, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@338055eb, org.springframework.security.web.context.SecurityContextHolderFilter@3a2d8a59, org.springframework.security.web.header.HeaderWriterFilter@50830605, org.springframework.security.web.authentication.logout.LogoutFilter@5879007b, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@2bf425d7, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3022c8b8, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@2ae7a4be, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@39d014d1, org.springframework.security.web.access.ExceptionTranslationFilter@4bd290c2, org.springframework.security.web.access.intercept.AuthorizationFilter@43525956]
2023-01-11T15:53:50.299+05:30 INFO 177140 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-01-11T15:53:50.462+05:30 INFO 177140 --- [ restartedMain] com.web.ecommerce.EcommerceApplication : Started EcommerceApplication in 7.986 seconds (process running for 8.765)
2023-01-11T15:53:50.545+05:30 INFO 177140 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-01-11T15:53:50.570+05:30 INFO 177140 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2023-01-11T15:53:50.628+05:30 INFO 177140 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.


Подробнее здесь: https://stackoverflow.com/questions/750 ... eb-servlet
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»