加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

SpringBoot:找不到匹配的bean异常

发布时间:2020-12-15 01:35:32 所属栏目:大数据 来源:网络整理
导读:我想在我的第一个SpringBoot应用程序中启动我的登录页面: 主类 @SpringBootApplicationpublic class MainGate extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { r

我想在我的第一个SpringBoot应用程序中启动我的登录页面:

主类

@SpringBootApplication

public class MainGate extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MainGate.class);
    }

    public static void main(String... args) {
        System.out.println("Booting .. ");
        SpringApplication.run(MainGate.class,args) ;
    }

}

这是我的Gradle文件

buildscript {
    ext {
        springBootVersion = '1.5.4.RELEASE'
    }
    repositories {
        maven {
            url "http://masked_domain/repository/external-proxy-group/"
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
}
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group = 'com.arun'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

task fatJar(type: Jar) {
    manifest {
        attributes(
            'Implementation-Title': 'Arun Spring Boot Application','Implementation-Version': version,'Built-By': System.getProperty('user.name'),'Built-Date': new Date(),'Main-Class':  'com.arun.MainGate','Built-JDK': System.getProperty('java.version')
        )
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

repositories {
        maven {
            url "http://masked_domain/repository/external-proxy-group/"
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testImplementation 'junit:junit:4.12'
}

应用属性文件

spring.mvc.view.prefix: jsp/
spring.mvc.view.suffix: .jsp

logging.level.org.springframework=debug

资源文件夹

enter image description here

控制器类

@Controller
public class CommonController {

    @RequestMapping("/")
    public String home(Map

我得到的例外

 017-10-20 17:01:28.568 TRACE 6704 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Invoking 'com.arun.controller.CommonController.home' with arguments [{}]
Reached the homeContoller
2017-10-20 17:01:28.568 TRACE 6704 --- [nio-8080-exec-1] .w.s.m.m.a.ServletInvocableHandlerMethod : Method [com.arun.controller.CommonController.home] returned [sso_arch]
2017-10-20 17:01:28.574 DEBUG 6704 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html,application/xhtml+xml,image/webp,image/apng,application/xml;q=0.9,*/*;q=0.8] based on Accept header types and producible media types [*/*])
2017-10-20 17:01:28.574 DEBUG 6704 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver  : No matching bean found for view name 'sso_arch'
2017-10-20 17:01:28.577 DEBUG 6704 --- [nio-8080-exec-1] o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'sso_arch'

How to configure spring boot mvc app for JSP?中提到的解决方案无效.因此提出一个新的线程.

最佳答案
你找到了正确的问题,但似乎你没有在答案中添加解决方案,你需要Add an InternalResourceViewResolver

This ViewResolver allows us to set properties such as prefix or suffix to the view name to generate the final view page URL:

@Bean
public ViewResolver getViewResolver(){
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/jsp/");
    resolver.setSuffix(".jsp");
    resolver.setViewClass(JstlView.class);
    return resolver;
}

并确保你有依赖:


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读