鍍金池/ 問答/Java  Linux  HTML/ webpack+vue開發(fā)打包的項(xiàng)目放到服務(wù)器上訪問不了

webpack+vue開發(fā)打包的項(xiàng)目放到服務(wù)器上訪問不了

我在本地使用vue-cli搭建的項(xiàng)目,tomcat端口號(hào)是8080,我自己作了一下把webpack配置的端口號(hào)改為8088,目的是為了鍛煉自己跨域調(diào)接口的能力。本地都o(jì)k,都能跑,但是使用npm run build打包后放到服務(wù)器上的tomcat下的webapps文件夾下沒有作用。
我訪問ip:8080顯示的是tomcat頁(yè)面而不是我項(xiàng)目的頁(yè)面,后面加上項(xiàng)目名就報(bào)404,仔細(xì)看看本地也是localhost:8088/#/,后面并沒有項(xiàng)目名能訪問啊,為什么在服務(wù)器上不能訪問呢?
后來懷疑是不是服務(wù)器有問題,因?yàn)槭俏易蛱觳挪攘藷o數(shù)坑搭好的,把老項(xiàng)目放上去完全能跑,說明服務(wù)器沒問題啊,那么只能是我自己項(xiàng)目的問題了,可是個(gè)人真的蠻菜的,始終不知道為什么,只能來社區(qū)求助了,謝謝前輩們了!

web.xml配置

<!-- 項(xiàng)目名稱 -->
    <display-name>degree</display-name>
    
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    
    <!-- 配置監(jiān)聽器 -->
    <listener>     
         <listener-class>
            org.springframework.web.context.ContextLoaderListener
         </listener-class> 
    </listener> 
    <listener>
         <listener-class>
             org.springframework.web.util.IntrospectorCleanupListener
         </listener-class> 
    </listener>
    
    <!-- 配置過濾器,解決POST亂碼問題 -->
    <filter>
         <filter-name>encoding</filter-name>
         <filter-class>
             org.springframework.web.filter.CharacterEncodingFilter
         </filter-class>
         <init-param>
             <param-name>encoding</param-name>
             <param-value>UTF-8</param-value>
         </init-param>
    </filter>
    <filter-mapping>     
         <filter-name>encoding</filter-name>
         <url-pattern>/*</url-pattern> 
    </filter-mapping>
    
    <servlet>
        <servlet-name>degree</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:springmvc-servlet.xml
            </param-value>

        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>degree</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

springmvc-servlet.xml:

<!-- 默認(rèn)的注解映射的支持,自動(dòng)注冊(cè)DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter,這個(gè)主要是作用于controller -->
    <mvc:annotation-driven />
    
    
    <!-- 啟用spring mvc 注解 -->
    <context:annotation-config />

    <!-- 掃包 -->
    <context:component-scan base-package="com.degree.controller.*">
        
    </context:component-scan>

    <!-- 對(duì)轉(zhuǎn)向頁(yè)面的路徑解析 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="" />
        <property name="suffix" value="" />  <!-- 可為空 -->
    </bean>

webpack配置文件index.js:

const path = require('path')

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/degree': {
        target: 'http://localhost:8080',
        pathRewrite: {'^/': '/'},
        changeOrigin: true
      }
    },

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8088, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: true,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: true,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,

    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false,
  },

  build: {
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}

圖片描述

圖片描述

回答
編輯回答
乞許

仔細(xì)看了下服務(wù)器后臺(tái),tomcat正常啟動(dòng)了但是沒有加載我的項(xiàng)目,其他項(xiàng)目沒有問題,我就草了

2018年1月27日 01:51