Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

有两个模块,如何让这两个模式的url地址能同时访问

我现在有两个模块,abbott-system模块和abbott-generator模块

我的模块abbott-system有url为/exp/list 模块abbott-generator有url为/article/list,我希望启动模块abbott-system后,b模块的abbott-generator为/article/list也有效,请问怎么实现呢?abbott-system模块和abbott-generator使用不同的端口号

abbott-system模块

http://127.0.0.1:9091/abo/exp/findAll

这是url可以被访问到

我的启动函数在这个模块下

abbott-generator模块

http://127.0.0.1:9090/aggregation/v1?start=0&dataLength=100

这是url访问不到

abbott-system模块

这是启动文件,只有abbott-system模块的/article/list有效,abbott-generator为/article/list访问不了

package cn;

//import cn.spring.inter.config.CorsFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

/**
 * 默认 SpringBoot 会扫描主类所在包 及子包下组件
 */
@SpringBootApplication
//@ComponentScan(basePackages= {"cn.spring.inter.controller"})//扫描组件
//@EntityScan("cn.spring.inter.bean")
//@EnableJpaRepositories("cn.spring.inter.repository")
//@MapperScan({"cn.spring.inter.*.Mapper","org.example.*.mapper"})
public class AbbottApplication {
    public static void main(String[] args) {
        SpringApplication.run(AbbottApplication.class, args);
    }
//    /**
//     * 配置跨域访问的过滤器
//     * @return
//     */
//    @Bean
//    public FilterRegistrationBean registerFilter(){
//        FilterRegistrationBean bean = new FilterRegistrationBean();
//        bean.addUrlPatterns("/*");
//        bean.setFilter(new CorsFilter());
//        return bean;
//    }
}
package cn.spring.inter.controller;

import cn.spring.inter.bean.ResponseData;
import cn.spring.inter.entity.AbbottExperience;
import cn.spring.inter.service.AbbottExperienceService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
//@RequestMapping("/abo/exp")
public class AbbottExperienceController {
    @Autowired
    private AbbottExperienceService abbottExperienceService;
    @RequestMapping("/abo/exp/findAll")
    public List<AbbottExperience> findAll(){
        return abbottExperienceService.findAll();
    }

    @RequestMapping(value = "/abo/exp/v1/addOne", method={ RequestMethod.POST, RequestMethod.GET })
    public ResponseData addOne(@RequestBody Map<String, String> experience){
        AbbottExperience abb=new AbbottExperience();
        abb.setCompany(experience.get("company"));
        abb.setInfo(experience.get("info"));
        abbottExperienceService.addOne(abb);
//        System.out.println(abb.getId());
        ResponseData responseData = new ResponseData();
        JSONObject jsonResultObject = new JSONObject();
        responseData.setCode("0000");
        responseData.setStatus("success");
        responseData.setMessage("add");
        responseData.setDetail("添加个人经历");
        jsonResultObject.put("data", abb);
        responseData.setResult(jsonResultObject);
        return responseData;
    }

    @RequestMapping(value = "/abo/exp/v1/updateOne", method={ RequestMethod.POST, RequestMethod.GET })
    public ResponseData updateOne(@RequestBody Map<String, String> experience){
        AbbottExperience abb=new AbbottExperience();
        abb.setId(Integer.parseInt(experience.get("id")));
        abb.setCompany(experience.get("company"));
        abb.setInfo(experience.get("info"));
        abbottExperienceService.updateOne(abb);
//        System.out.println(abb.getId());
        ResponseData responseData = new ResponseData();
        JSONObject jsonResultObject = new JSONObject();
        responseData.setCode("0000");
        responseData.setStatus("success");
        responseData.setMessage("add");
        responseData.setDetail("添加个人经历");
        jsonResultObject.put("data", abb);
        responseData.setResult(jsonResultObject);
        return responseData;
    }

    @RequestMapping(value="/abo/exp/v1",method=RequestMethod.GET)
    public ResponseData getAll(
            @RequestParam(value="start", required=false,defaultValue = "0") Integer start,
            @RequestParam(value="dataLength", required=false,defaultValue = "100") Integer dataLength){
//        System.out.println("start="+start+"/dataLength="+dataLength);

        ResponseData responseData = new ResponseData();
        JSONObject jsonResultObject = new JSONObject();
        responseData.setCode("200");
        responseData.setStatus("success");
        responseData.setMessage("abbottExperiences");
        responseData.setDetail("查询Experiences");
        List<AbbottExperience> abbottExperienceList = abbottExperienceService.getAll(start, dataLength);
        jsonResultObject.put("experience", abbottExperienceList);
        responseData.setData(jsonResultObject);
        return responseData;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

访问地址不应该是http://ip:端口/url吗,你两个项目端口不同,url不冲突啊


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...