V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
7911364440
V2EX  ›  程序员

maven 依赖的问题

  •  
  •   7911364440 · 2022-04-08 16:27:07 +08:00 · 1218 次点击
    这是一个创建于 720 天前的主题,其中的信息可能已经有所发展或是发生改变。

    maven 项目,模块 1 依赖模块 2 ,模块 2 中加了跨域的配置,现在的问题是模块 1 还是会出现跨域的问题,如果把这段配置放到模块 1 中就没问题。 想问下为啥模块 1 中引入不了跨域的配置啊?

    @Configuration
    public class WebConfiguration implements WebMvcConfigurer {
    
        @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            converters.clear();
            converters.add(0, new MappingJackson2HttpMessageConverter());
        }
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOriginPatterns("*")
                    .allowCredentials(true)
                    .allowedMethods("GET", "POST", "DELETE", "PUT")
                    .maxAge(3600)
                    .allowedHeaders("*");
        }
    }
    
    6 条回复    2022-04-09 02:20:58 +08:00
    wolfie
        1
    wolfie  
       2022-04-08 16:37:47 +08:00   ❤️ 1
    检查包路径,有没有扫描到。
    zilongzixue
        2
    zilongzixue  
       2022-04-08 16:43:08 +08:00   ❤️ 1
    包名前缀要与启动类目录一致
    7911364440
        3
    7911364440  
    OP
       2022-04-08 16:47:27 +08:00
    @zilongzixue
    @wolfie
    的确是包路径问题,感谢两位大佬!
    CRUD
        4
    CRUD  
       2022-04-08 16:51:46 +08:00
    1L + 1 ,springboot 启动默认从启动类当前包路径开始扫包,`WebConfiguration`所在的包如果不在模块 1 的启动类当前包或者子包内,是不会被扫到并注入到 spring 里面的,需要手动指定一下扫包配置。
    Edsie
        5
    Edsie  
       2022-04-08 16:56:43 +08:00
    最好做成 Starter
    Bingchunmoli
        6
    Bingchunmoli  
       2022-04-09 02:20:58 +08:00
    @Edsie 之前有想过做 redis 的 config 的 starter(因为通常都需要 json 的序列化),然后发现写起来和使用都不太会,甚至不知道能不能发到中央仓库。就搁置了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1266 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:53 · PVG 01:53 · LAX 10:53 · JFK 13:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.