Maven项目结构问题。

如图 1 所示,security-broswer 项目是一个普通的 maven 项目,security-demo 是一个 spring boot 项目,security-demo 的依赖有 security-broswer 项目,在 security-broswer 中写的想配置,API都不生效。

clipboard.png
图1
比如,在 security-broswer 中写了一个如下 Controller

//在 security-broswer 中
package com.forwy.security.browser.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    
    @RequestMapping(value = "/user",method = RequestMethod.GET)
    public String query(){
        return "test";
    }

}

启动 security-demo 后放问 /user404 ,但是如果在 security-demo 中有一个类继承了这个 UserController 之后就可以正常访问 /user

在 security-demo 中
package com.forwy.securitydemo.controller;

import org.springframework.web.bind.annotation.RestController;

import com.forwy.security.browser.controller.UserController;

@RestController
public class TestController extends UserControllers {

}

经测试,其他如config,compant等是这样,必须在 security-demo 中做一下继承才生效。
请问各位大佬,这是怎么回事!!
快崩溃了~~

阅读 2.7k
2 个回答

是不是因为包名的原因,你security-demo项目里的的启动类放在com.forwy.securitydemo包下,而security-broswer里的controller类在com.forwy.security.browser.controller,不在同一个包下,没被扫描到

你说的有道理,我怎么就没想到呢。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题