亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

若依前后端打成一個JAR包部署的完整步驟

 更新時間:2025年01月21日 08:48:02   作者:噫吁嚱?。?!  
這篇文章主要介紹了如何將若依前后端分離項目打包成jar,不使用nginx轉(zhuǎn)發(fā),前端修改了路由模式和環(huán)境變量配置,后端增加了依賴、配置了Thymeleaf和訪問路徑,需要的朋友可以參考下

客戶需要將項目前后端作為一個整體打包成jar,不使用nginx方式轉(zhuǎn)發(fā)。使用框架是若依前后端分離,后端springboot,前端vue,目的就是把vue打入jar。

一、前端修改

  • ruoyi-ui/src/router/index.js文件 ,將 mode: ‘history’ 改成 mode: ‘hash’
    export default new Router({
      mode: 'hash', 
      scrollBehavior: () => ({ y: 0 }),
      routes: constantRoutes
    })
    

    2、修改ruoyi-ui/.env.production文件

    說明:VUE_APP_BASE_API = '/prod-api'是原來,我這前后端加了訪問路徑如VUE_APP_BASE_API = '/ReportApi'
    #VUE_APP_BASE_API = '/prod-api'
    VUE_APP_BASE_API = '/ReportApi'

    3、修改vue.config.js

二、后端修改

1、ruoyi-admin pom文件加入以下依賴

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

2、增加配置文件  (dev和local可以都改),增加thymeleaf配置和訪問路徑配置

  #前后端打成一個JAR包配置
  thymeleaf:
    prefix: classpath:/dist/
    mode: HTML
    encoding: utf-8
    cache: false

3、修改ResourcesConfig文件內(nèi)容,新增以下部分addViewControllers

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index.html");
        registry.addViewController("/").setViewName("index.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

4、修改ResourcesConfig文件內(nèi)容,替換addResourceHandlers內(nèi)容如下:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    /** 本地文件上傳路徑 */
    registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/");
    /** 頁面靜態(tài)化 */
    registry.addResourceHandler("/static/**").addResourceLocations("classpath:/dist/static/");
    /** swagger配置 */
    registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}

5、根據(jù)情況配置訪問權(quán)限修改ruoyi-framework項目中的SecurityConfig.java類,配置靜態(tài)資源訪問權(quán)限

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception
    {
        // 注解標(biāo)記允許匿名訪問的url
        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests();
        permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll());

        httpSecurity
                // CSRF禁用,因為不使用session
                .csrf().disable()
                // 禁用HTTP響應(yīng)標(biāo)頭
                .headers().cacheControl().disable().and()
                // 認(rèn)證失敗處理類
                .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
                // 基于token,所以不需要session
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                // 過濾請求
                .authorizeRequests()
                // 對于登錄login 注冊register 驗證碼captchaImage 允許匿名訪問
                .antMatchers("/login", "/register", "/captchaImage").permitAll()
                // 靜態(tài)資源,可匿名訪問
                .antMatchers(HttpMethod.GET, "/**/**","/**","/index","/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
                .antMatchers("/test/**","/aicccms/**","/ICD/**").permitAll()
                // 除上面外的所有請求全部需要鑒權(quán)認(rèn)證
                .anyRequest().authenticated()
                .and()
                .headers().frameOptions().disable();
        // 添加Logout filter
        httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
        // 添加JWT filter
        httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
        // 添加CORS filter
        httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
        httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class);
    }

6、將前端dist移動到resources目錄下

總結(jié) 

到此這篇關(guān)于若依前后端打成一個JAR包部署的文章就介紹到這了,更多相關(guān)若依前后端打JAR包部署內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java  interface 接口的使用好處分析

    java interface 接口的使用好處分析

    這篇文章主要介紹了java interface 接口的使用好處,結(jié)合實例形式分析了java interface接口的功能、基本使用方法及多態(tài)性的使用優(yōu)點,需要的朋友可以參考下
    2019-11-11
  • Springboot shiro認(rèn)證授權(quán)實現(xiàn)原理及實例

    Springboot shiro認(rèn)證授權(quán)實現(xiàn)原理及實例

    這篇文章主要介紹了Springboot shiro認(rèn)證授權(quán)實現(xiàn)原理及實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • 最新評論