Whitelabel Error Page

springboot 启动后通过网页访问出现如下错误:http://localhost:9999/user/

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Jan 04 11:16:27 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available

原因是 包的命名问题

例如 你的 包命名为 com.julongtech.main springboot启动类位于此包下

package com.julongtech.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication  // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class ProviderUserApplication {

	public static void main(String[] args) throws Exception {
		SpringApplication.run(ProviderUserApplication.class, args);
	}
	
}

如果你重新定义了一个 action 包  名字是 com.julongtech.action 这样子

package com.julongtech.action;

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

import com.julongtech.entity.UserInfo;

@RestController
public class UserAction {
	
	@RequestMapping(value="/user")
	public String home() {
		return "Hello World!";
	}
	
	@RequestMapping(value="/user/{userId}")
	public UserInfo findById(@PathVariable String userId){
		UserInfo user = new UserInfo();
		user.setUserId("A0001");
		user.setUserName("测试数据");
		return user;
	}
}

这样子 启动就不会扫描自己创建的包,默认springboot启动扫描的是 启动类所在的包的和他的子包

解决方法

1.将springboot启动类 直接由com.julongtech.main 包放到 com.julongtech包下即可解决

2.自定义扫描的包在启动类加入 @ComponentScan(basePackages={"com.julongtech"})

package com.julongtech.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication  // same as @Configuration @EnableAutoConfiguration @ComponentScan
@ComponentScan(basePackages={"com.julongtech"})
public class ProviderUserApplication {

	public static void main(String[] args) throws Exception {
		SpringApplication.run(ProviderUserApplication.class, args);
	}
	
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值