我在Spring Boot中编写了代码,但运行时却无法正常工作。请不要谈论软件包,因为我已经做了所有事情,并请您就此问题帮助我。
非常感谢您的关注
这是我的Restcontroller课
@org.springframework.web.bind.annotation.RestController public class RestController { @Autowired StudentService studentService;
@RequestMapping(value = "/",method = RequestMethod.GET)
public ResponseEntity<List<Student>>getAll(){
List<Student>getAll=studentService.getAll();
return new ResponseEntity<List<Student>>(getAll, HttpStatus.OK);
}
} 这是我的控制器课
@Controller public class MyController {
@RequestMapping("/")
public String home(){
return "index";
}
}
并且也有存储库和服务类(带有接口)
这是我的主要角度代码
"use strict"
var app=angular.module('myApp',[]); 这是我的角度控制器课程
app.controller('myCtrl',['$scope','myFactory',function ($scope,userService) { var self=this; self.users=[];
getAllData();
function getAllData() {
userService.getAllData()
.then(function (value) {
self.users=value;
},function (reason) {
console.log('Error');
});
}
}]); 最后一个是我的角度服务
app.factory('myFactory',['$http','$q',function ($http,$q) { var uri='href="localhost:8080/"'; var factory={getAllData:getAllData};
return factory;
function getAllData() {
var deferred=$q.defer();
$http.get(uri)
.then(function (response) {
deferred.resolve(response.data);
},function (reason) {
deferred.reject(reason);
});
return deferred.promise;
}
}]); 亲爱的开发人员我在运行该项目时遇到了白色标签错误。不要知道但我认为这是角度编码中的问题。...也许...请帮助我解决该问题
还有一个是我的配置文件应用程序
@Configuration @EnableWebMvc public class MyConfiguration extends WebMvcConfigurerAdapter { @Override public void configureViewResolvers(ViewResolverRegistry registry) { InternalResourceViewResolver internalResourceViewResolver=new InternalResourceViewResolver(); internalResourceViewResolver.setPrefix("/WEB-INF/"); internalResourceViewResolver.setSuffix(".html"); registry.viewResolver(internalResourceViewResolver); }
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
}
spring.datasource.url=jdbc:mysql://localhost:3306/employee101 spring.datasource.username=root spring.datasource.password= 帮助我进行了与数据库没有连接的项目,它可以正常工作。我已打开登录页面(不是矿山弹簧登录页面-我是默认登录页面)。但毕竟它没有打开任何东西。只是向我显示WHITELABEL错误。我搜索了仅显示包装错误的所有Internet。但将我的演示应用程序类放在软件包的顶部。我的意思是,分类套餐就是这样-打包HHH.com.demo; 和其他课程都在该软件包中-HHH.COM.DEMO.BLA BLA BLA。请说解决方案不实施错误等级,或者其他无法证明错误的方式。我的意思是我需要使用它和解决方案,而不是远离它
谢谢您的关注!!!
问题来源于stack overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
从你的描述来看,你遇到了Spring Boot应用中的“White Label Error Page”问题,这通常意味着Spring Boot在处理请求时没有找到合适的视图来渲染错误页面。根据你提供的信息,这里有几个可能的问题和解决方法:
Angular路由与Spring Boot的视图解析冲突: Angular使用前端路由(如#/someRoute
),而Spring Boot默认寻找物理视图文件(如.html
)。如果你的应用是单页面应用(SPA),确保Spring Boot不对Angular的路由进行处理。你可以通过以下方式配置Spring Boot以忽略对静态资源的路由处理:
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/{spring:\\w+}").setViewName("forward:/");
registry.addViewController("/**/{spring:\\w+}").setViewName("forward:/");
registry.addViewController("/{spring:\\w+}/**/{spring:\\w+}").setViewName("forward:/");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.resourceChain(true)
.addResolver(new PathResourceResolver());
}
}
这段代码告诉Spring Boot将所有未知路径转发到index.html,让Angular自己处理路由。
确保静态资源正确配置: 你已经配置了静态资源的处理,但请确认/static/**
映射是否指向了正确的目录,即Angular构建后的静态文件所在位置。如果Angular应用被打包后放置在src/main/resources/static
下,那么你的配置看起来是正确的。但是,请检查实际部署时这些资源是否被正确地包含和访问。
检查Angular服务中的URL: 在你的Angular服务中,你设置的URI为var uri='href="localhost:8080/"';
,这里的格式似乎有误。应该直接是一个字符串表示的URL路径,不需要包含href=
。修改为如下:
var uri = 'http://localhost:8080/';
数据库连接问题: 虽然你说项目可以在不连接数据库的情况下运行,但确保数据库配置正确仍然是重要的。你提到的数据库URL、用户名和密码部分被省略了,确保它们在你的application.properties
或application.yml
文件中被正确填写,并且数据库服务正在运行。
打包结构: 你提到了包结构问题,虽然你已将其放在首位,但请再次确认所有的类都位于正确的包下,特别是主启动类需要在包含其他组件的包或者其子包内,以确保Spring Boot的自动扫描机制能正常工作。
查看日志: 最重要的是查看应用的日志输出,它会提供关于为什么无法找到视图或其他潜在问题的详细信息。Spring Boot启动时和处理请求时的日志可能会揭示导致白屏错误的具体原因。
综上所述,首先尝试调整Spring Boot的配置以适应SPA的前端路由,然后检查静态资源路径和服务中的URL格式,同时关注应用日志以获取更多线索。