webjar没有加载在spring启动应用程序中

时间:2016-08-29 05:59:04

标签: java spring-boot webjars

在春季启动应用程序中,无法从webjar加载jscss。我添加了所需的依赖项,我能够看到罐子。

<script src="webjars/core-js/client/shim.min.js"></script>
<script src="webjars/zone.js/dist/zone.js"></script>
<script src="webjars/reflect-metadata/Reflect.js"></script>
<script src="webjars/systemjs/dist/system.src.js"></script>

这给出了404错误,我还添加了以下配置以解决此问题仍然没有用。

    @Configuration
    @EnableWebMvc

        public class WebConfig extends WebMvcConfigurerAdapter {

            public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
                configurer.enable();
            }

            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
                registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
            }


        /*  *//**
           * 
           * @return ViewResolver
           */
            @Bean
            public ViewResolver getViewResolver() {
                InternalResourceViewResolver resolver = new InternalResourceViewResolver();
                resolver.setPrefix("/");
                resolver.setSuffix(".html");
                return resolver;
            }

我的POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.abc.xyz</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description></description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__common</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__compiler</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__core</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__forms</artifactId>
            <version>0.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__http</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__platform-browser</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__platform-browser-dynamic</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__router</artifactId>
            <version>3.0.0-rc.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__router-deprecated</artifactId>
            <version>2.0.0-rc.2</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular__upgrade</artifactId>
            <version>2.0.0-rc.5</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>systemjs</artifactId>
            <version>0.19.27</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>core-js</artifactId>
            <version>2.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>reflect-metadata</artifactId>
            <version>0.1.3</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>rxjs</artifactId>
            <version>5.0.0-beta.6</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>zone.js</artifactId>
            <version>0.6.12</version>
        </dependency>

        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>angular2-in-memory-web-api</artifactId>
            <version>0.0.15</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

请帮忙

1 个答案:

答案 0 :(得分:0)

您正在引用名为 webjars / core-js / client / shim.min.js 的文件,但是,这不是文件的正确路径,除非您是使用 webjars-locator ,根据their documentation提供与版本无关的路径:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>webjars-locator</artifactId>
</dependency>

在你提到的评论中,Spring引发自己添加了这种依赖,但事实并非如此。 Spring引导确实列出了依赖项,但只在<dependencyManagement> section中,这与添加依赖项不同。

Spring Web MVC还将其列为依赖项,但作为optional dependency,这意味着您必须明确添加它。