- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个半工作(如可运行)的 Spring Boot Web 应用程序,我正在尝试为其添加安全性。我有一个可以使用 OAuth2 的 REST 服务,但我还需要在 WebMvc 端进行身份验证。我无法按照我的方式让它工作,所以我重构了配置:
public class SpringConfigurationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer
{
@Override
protected Class<?>[] getRootConfigClasses()
{
return new Class[] { AppConfiguration.class };
}
@Override
protected Class<?>[] getServletConfigClasses()
{
return null;
}
@Override
protected String[] getServletMappings()
{
return new String[] { "/" };
}
}
和
@Configuration
@ComponentScan(basePackages = {"co.sens.rest", "co.sens.data", "co.sens.docdata", "co.sens.aggregators"})
@Import({ WebMvcConfig.class, OAuth2ServerConfig.class, SecurityConfiguration.class, CustomUserDetailsService.class })
public class AppConfiguration {
}
因此,其目的是扫描应用程序本身(co.sens.rest)中的组件以及引用的 jar 中的外部代码。主要目的是保持数据访问分离。
自从这样做以来,我现在收到以下错误,据我所知,这是因为 Spring Security 启动得太早了。它正在尝试为我的自定义 UserDetailsService Autowiring 我的 UserRepository。
在添加 AbstractAnnotationConfigDispatcherServletInitializer 之前,我可以让它运行,但无法让 Web 端的安全性发挥作用
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedServletContainerCustomizerBeanPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private co.sens.rest.config.SecurityConfiguration co.sens.rest.config.MethodSecurityConfig.securityConfig; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.setConfigurers(java.util.List); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private co.sens.rest.controllers.UsersController co.sens.rest.controllers.web.WebController.usersController; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private co.sens.data.Operations co.sens.rest.controllers.UsersController.dataOperations; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'operations': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private co.sens.docdata.DocStoreOperations co.sens.data.Operations.docStoreOperations; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'docStoreOperations': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private co.sens.docdata.repositories.UserRepository co.sens.docdata.DocStoreOperations.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@553a3d88: startup date [Fri Jul 10 08:55:21 BST 2015]; root of context hierarchy
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:232)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at co.sens.rest.Application.main(Application.java:11)
完整堆栈跟踪:http://pastebin.com/SJLa2pSc
更新
配置:
package co.sens.rest.config;
@Configuration
@ComponentScan(basePackages = {"co.sens.data", "co.sens.docdata", "co.sens.aggregators"})
public class AppConfiguration {
}
public class MessageSecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
@Configuration
public class OAuth2ServerConfig {
private static final String SENS_RESOURCE_ID = "sens";
@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) {
resources.resourceId(SENS_RESOURCE_ID).stateless(false); //.authenticationEntryPoint(new RestAuthenticationEntryPoint()); //.stateless(false);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api").access("#oauth2.hasScope('read') and hasRole('ROLE_USER')");
}
}
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Autowired
private TokenStore tokenStore;
@Autowired
private UserApprovalHandler userApprovalHandler;
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
private CustomUserDetailsService userDetailsService;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("sensapp")
.resourceIds(SENS_RESOURCE_ID)
.authorizedGrantTypes("authorization_code", "refresh_token",
"password")
.authorities("USER")
.scopes("read", "write")
.secret("secret");
}
@Bean
public TokenStore tokenStore() {
return new InMemoryTokenStore();
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.tokenStore(tokenStore)
.userApprovalHandler(userApprovalHandler)
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService);
}
@Bean
@Primary
public DefaultTokenServices tokenServices() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setSupportRefreshToken(true);
tokenServices.setTokenStore(this.tokenStore);
return tokenServices;
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.realm("sens/client");
}
}
protected static class Approvals {
@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
private TokenStore tokenStore;
@Bean
public ApprovalStore approvalStore() throws Exception {
TokenApprovalStore store = new TokenApprovalStore();
store.setTokenStore(tokenStore);
return store;
}
@Bean
@Lazy
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public SensUserApprovalHandler userApprovalHandler() throws Exception {
SensUserApprovalHandler handler = new SensUserApprovalHandler();
handler.setApprovalStore(approvalStore());
handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
handler.setClientDetailsService(clientDetailsService);
handler.setUseApprovalStore(true);
return handler;
}
}
}
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}
}
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/web/**").authenticated()
.antMatchers("/login/**", "/resources/**").permitAll()
.and()
.formLogin().loginProcessingUrl("/login").failureUrl("/login?authorization_error=true").defaultSuccessUrl("/web/home").loginPage("/login").permitAll()
.and()
.logout().logoutUrl("/logout").logoutSuccessUrl("/login")
.permitAll();
}
@Autowired
private UserDetailsService userDetailsService;
@Autowired
public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
public class ServletInitializer extends AbstractDispatcherServletInitializer {
@Override
protected WebApplicationContext createServletApplicationContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.scan(ClassUtils.getPackageName(getClass()));
return context;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
protected WebApplicationContext createRootApplicationContext() {
return null;
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain");
filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");
servletContext.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(null, false, "/*");
}
}
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
//@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/")
.setCachePeriod(31556926);
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
@Bean
public TemplateResolver defaultTemplateResolver() {
TemplateResolver result = new ServletContextTemplateResolver();
result.setPrefix("/WEB-INF/templates/");
result.setSuffix(".html");
result.setTemplateMode("LEGACYHTML5");
result.setCacheable(false); // TODO Only for dev
return result;
}
@Bean
public SpringTemplateEngine templateEngine(TemplateResolver templateResolver) {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Set<IDialect> dialects = new HashSet<>();
dialects.add(new SpringSecurityDialect());
templateEngine.setAdditionalDialects(dialects);
return templateEngine;
}
@Bean
public ThymeleafViewResolver viewResolver(SpringTemplateEngine templateEngine) {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine);
return viewResolver;
}
@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
defaultView.setExtractValueFromSingleKeyModel(true);
ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
return contentViewResolver;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
安全调试日志
2015-07-14 14:05:31.352 INFO 12373 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2015-07-14 14:05:31.352 INFO 12373 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2015-07-14 14:05:31.387 INFO 12373 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 35 ms
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/oauth/token']
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/web/home'; against '/oauth/token'
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/oauth/token_key']
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/web/home'; against '/oauth/token_key'
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/oauth/check_token']
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/web/home'; against '/oauth/check_token'
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.web.util.matcher.OrRequestMatcher : No matches found
2015-07-14 14:05:31.460 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration$NotOAuthRequestMatcher@7d97df04
2015-07-14 14:05:31.461 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.web.util.matcher.OrRequestMatcher : matched
2015-07-14 14:05:31.462 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2015-07-14 14:05:31.462 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2015-07-14 14:05:31.463 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2015-07-14 14:05:31.463 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.header.writers.HstsHeaderWriter : Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@63d700f9
2015-07-14 14:05:31.463 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter'
2015-07-14 14:05:31.463 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/web/home'; against '/logout'
2015-07-14 14:05:31.464 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 5 of 11 in additional filter chain; firing Filter: 'OAuth2AuthenticationProcessingFilter'
2015-07-14 14:05:31.464 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.o.p.a.BearerTokenExtractor : Token not found in headers. Trying request parameters.
2015-07-14 14:05:31.464 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.o.p.a.BearerTokenExtractor : Token not found in request parameters. Not an OAuth2 request.
2015-07-14 14:05:31.464 DEBUG 12373 --- [nio-8080-exec-1] p.a.OAuth2AuthenticationProcessingFilter : No token in request, will continue chain.
2015-07-14 14:05:31.464 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2015-07-14 14:05:31.464 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2015-07-14 14:05:31.465 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2015-07-14 14:05:31.466 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.a.AnonymousAuthenticationFilter : Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@9055e4a6: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
2015-07-14 14:05:31.467 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter'
2015-07-14 14:05:31.467 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.session.SessionManagementFilter : Requested session ID 09564785AF0DDD41AB2645CEEE04E79E is invalid.
2015-07-14 14:05:31.467 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2015-07-14 14:05:31.467 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2015-07-14 14:05:31.467 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/web/home'; against '/api'
2015-07-14 14:05:31.467 DEBUG 12373 --- [nio-8080-exec-1] o.s.s.w.a.i.FilterSecurityInterceptor : Public object - authentication not attempted
2015-07-14 14:05:31.468 DEBUG 12373 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /web/home reached end of additional filter chain; proceeding with original chain
2015-07-14 14:05:31.622 ERROR 12373 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": Error retrieving value for property "username" of authentication object of class org.springframework.security.authentication.AnonymousAuthenticationToken (index)
2015-07-14 14:05:31.624 DEBUG 12373 --- [nio-8080-exec-1] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed
2015-07-14 14:05:31.626 ERROR 12373 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error retrieving value for property "username" of authentication object of class org.springframework.security.authentication.AnonymousAuthenticationToken (index)] with root cause
最佳答案
如果您使用 Spring Boot,则应删除 SpringConfigurationInitializer
并使用 SpringBootServletInitializer
。例如:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
详情请参阅Spring Boot引用。
关于java - Spring ComponentScan 导致 java.lang.IllegalStateException : ApplicationEventMulticaster not initialized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31335597/
我看到我们有 @org.springframework.context.annotation.ComponentScans 和 @org.springframework.context.annotat
我想向我的 Spring WebApplicationContext 添加一个特定的 Controller 类。我遇到了以下示例:(它是 Scala 中的,但改编自此处: using Componen
场景复现 为了统一定制一个过滤器(Filter),所以在另外一个工程里面创建了一个过滤器,并通过jar包的方法导入当前项目,通过@ComponentScan({"org.example.
我为我的 Spring Application Context 进行了以下设置. @Configuration public class RmiContext { @Bean public R
我正在使用注释设置一个非常小的带有 Boot 的 Spring/REST/JPA 项目。 当我将 JPA 存储库类移到不同的包并在其包上调用 componentscan 时,我在具有 Autowire
我正在使用 Java 11 和 Spring 开发 JavaFX 应用程序。应用程序模块使用 jlink 与自定义 JRE 捆绑在一起,它只允许命名模块包含在 bundle 中。由于 Spring 不
我想找到以编程方式设置“@componentScan”的“basepackages”的方法。 我有这样的东西: @Configuration @EnableWebMvc @ComponentScan(
在我的 Spring Boot 项目中,我必须使用一个外部库,它在 Spring 上下文中定义了 beans。因此,在我的应用程序类中,我在下面添加了我的项目和外部库的基础包, @SpringBoot
@ComponentScan( //CS1 basePackages = {"com.package.A", "com.package.B"}, excludeFilters = @
@ComponentScan 将为您提供包中所有带有 @Component 注释的类的列表(或 @Service/@Repository).为此,我想他们使用反射来枚举包中的所有类并找到带有该注释的类
我的课上有以下 spring header @Service @EnableAutoConfiguration(exclude = {HibernateJpaAutoConfiguration.cla
我对 Spring 比较陌生,并且正在学习一些示例。 在其中一个示例中,我注意到 Spring 没有将 URI 映射到方法。 我发现我将 @ComponentScan 注释放在错误的配置类上并解决了我
我正在关注有关 Spring MVC 的教程,但我无法理解 @ComponentScan 的某些内容即使在阅读了 spring API 文档之后也可以进行注释,所以这里是示例代码: 配置 View C
我不知道如何在测试中排除配置(例如 described here )。我真正想要的是忽略 @WebMvcTest 中的配置,但即使下面的更简单的示例对我来说也不起作用: @ExtendWith(Spr
我有包裹一: xxx.yyy.zzz { SampleClass1.java } 和包二: xxx.yyy.zzz { SampleClass2.java } 并打包三个: aaa.bbb.ccc
“context:componentscan”可以扫描自定义注释吗?如果是这样,扫描后它会将扫描的 bean 存储在应用程序上下文中的什么位置?我如何访问结果? 最佳答案 我们在 XML 配置文件中注
我遇到了 @ComponentScan @Configuration 的问题测试类——即 @ComponentScan无意中拉入 @Configuration在集成测试期间。 例如,假设您在 src/
我有带有包布局的 spring boot 应用程序示例: main: -com.foo Application.java -com.foo.services Item
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭 7 年前。 Improve
我想在 Spring 中从基于 XML 的配置切换到基于 Java 的配置。现在我们的应用程序上下文中有这样的东西: 但是如果我写这样的东西...... @ComponentScan
我是一名优秀的程序员,十分优秀!