activiti自定义流程之Spring整合activiti-modeler5.16实例(二):创建流程模型

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: <p><span style="font-family:Arial; font-size:14px; line-height:26px">注:(1)环境搭建:<a target="_blank" href="http://blog.csdn.net/tuzongxun/article/details/50787822" style="color:rgb(255,153,0); text-d

注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建

1.maven导包,这里就没有什么多的好说了,直接代码:

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-beans</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-core</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-aop</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-context</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-webmvc</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-web</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-aspects</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-expression</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-tx</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>javax.servlet</groupId>
    	<artifactId>javax.servlet-api</artifactId>
    	<version>3.1.0</version>
    </dependency>
    <dependency>
    	<groupId>com.fasterxml.jackson.core</groupId>
    	<artifactId>jackson-annotations</artifactId>
    	<version>2.2.3</version>
    </dependency>
    <dependency>
    	<groupId>com.fasterxml.jackson.core</groupId>
    	<artifactId>jackson-core</artifactId>
    	<version>2.2.3</version>
    </dependency>
    <dependency>
    	<groupId>com.fasterxml.jackson.core</groupId>
    	<artifactId>jackson-databind</artifactId>
    	<version>2.2.3</version>
    </dependency>
    <dependency>
    	<groupId>org.activiti</groupId>
    	<artifactId>activiti-modeler</artifactId>
    	<version>5.16</version>
    </dependency>
    <dependency>
    	<groupId>org.activiti</groupId>
    	<artifactId>activiti-engine</artifactId>
    	<version>5.16</version>
    </dependency>
    <dependency>
    	<groupId>org.activiti</groupId>
    	<artifactId>activiti-explorer</artifactId>
    	<version>5.16</version>
    </dependency>
    <dependency>
    	<groupId>org.activiti</groupId>
    	<artifactId>activiti-rest</artifactId>
    	<version>5.16</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-context-support</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>mysql</groupId>
    	<artifactId>mysql-connector-java</artifactId>
    	<version>5.1.34</version>
    </dependency>

    <dependency>
    	<groupId>org.activiti</groupId>
    	<artifactId>activiti-spring</artifactId>
    	<version>5.16</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-jdbc</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.springframework</groupId>
    	<artifactId>spring-test</artifactId>
    	<version>4.0.9.RELEASE</version>
    </dependency>
    <dependency>
    	<groupId>org.activiti</groupId>
    	<artifactId>activiti-bpmn-converter</artifactId>
    	<version>5.16</version>
    </dependency>
    <dependency>
    	<groupId>org.codehaus.jackson</groupId>
    	<artifactId>jackson-core-asl</artifactId>
    	<version>1.9.11</version>
    </dependency>
    <dependency>
    	<groupId>org.codehaus.jackson</groupId>
    	<artifactId>jackson-mapper-asl</artifactId>
    	<version>1.9.11</version>
    </dependency>
  </dependencies>

2.基础配置:web.xml,这个也主要是spring相关的东西,不多说了:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">    
	<filter>
		<description>字符集过滤器</description>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<description>字符集编码</description>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<servlet>
    <servlet-name>RestletServlet</servlet-name>
    <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
    <init-param>
      <param-name>org.restlet.application</param-name>
      <param-value>org.activiti.rest.editor.application.ModelerRestApplication</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>RestletServlet</servlet-name>
    <url-pattern>/service/*</url-pattern>
  </servlet-mapping>
	
	
    <servlet>  
        <servlet-name>springMVC</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath:spring.xml</param-value>  
        </init-param>    
    </servlet>  
    <servlet-mapping>  
        <servlet-name>springMVC</servlet-name>  
        <url-pattern>*.do</url-pattern>  
    </servlet-mapping>
    <welcome-file-list>
    	<welcome-file>activiti.html</welcome-file>
    	<welcome-file>activiti.htm</welcome-file>
    	<welcome-file>activiti.jsp</welcome-file>
    	<welcome-file>default.html</welcome-file>
    	<welcome-file>default.htm</welcome-file>
    	<welcome-file>default.jsp</welcome-file>
    </welcome-file-list>  
</web-app>  

3.基础配置spring.xml:

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"    
    xsi:schemaLocation="  
        http://www.springframework.org/schema/beans   
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">  

    <context:annotation-config />  
    <mvc:annotation-driven />
    <context:component-scan base-package="controllers" />  
	<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
	   
	   <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
	   <property name="url" value="jdbc:mysql://192.168.0.201:3306/testtu?useUnicode=true&characterEncoding=utf8" ></property>
	   <property name="username" value="root" ></property> 
	   <property name="password" value="123456" ></property> 
	</bean>
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
	   <property name="dataSource" ref="dataSource"></property>
	</bean>
	
	<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource" />
		<property name="databaseSchemaUpdate" value="true" />
	    <property name="jobExecutorActivate" value="false"/>
	    <property name="history" value="full"/>
	    <property name="transactionManager" ref="transactionManager" />
		<!-- 配置事务管理器,统一事务 -->
		
		<!-- 设置建表策略,如果没有表,自动创建表 -->
	</bean>
	<!-- 创建流程引擎对象 -->
	<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
		<property name="processEngineConfiguration" ref="processEngineConfiguration" />
	</bean>

	<!-- 由流程引擎对象,提供的方法,创建项目中使用的Activiti工作流的Service -->
	<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
	<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
	<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
	<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
	<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
     
    <!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
	<bean id="mappingJacksonHttpMessageConverter"
		class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
				<value>text/html;charset=utf-8</value>
			</list>
		</property>
	</bean>

	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
			</list>
		</property>
	</bean>
    
</beans>  

4.模型实体类:

package model;

import java.util.Date;

public class ActivitiModel {
	private String id;
	private String name;
	private String key;
	private String description;
	private Date createTime;
	private Date lastUpdateTime;
	private int version;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public String toString() {
		return "ActivitiModel [id=" + id + ", name=" + name + ", key=" + key
				+ ", description=" + description + ", createTime=" + createTime
				+ ", lastUpdateTime=" + lastUpdateTime + ", version=" + version
				+ "]";
	}

}

5.后台业务代码,这里最后的操作是把跳转到acitiviti-modeler流程图设计界面的路径返回到了前端,然后让前端再跳转到流程图设计界面。

在我操作过程中,必须这样做才能实现设想的结果,因为我的前端使用的是angular js,页面上的路由跳转也都是由angular ui来控制,所以像第一篇spring整合activiti-modeler中那样从后台直接重定向的话就没有任何反应:

/**
	 * 创建模型
	 * 
	 * @author:tuzongxun
	 * @Title: create
	 * @param @param activiti
	 * @param @param request
	 * @param @param response
	 * @param @return
	 * @return Object
	 * @date Mar 17, 2016 12:30:29 PM
	 * @throws
	 */
	@RequestMapping(value = "/create.do", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object create(@RequestBody ActivitiModel activiti,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> map = new HashMap<String, String>();
		Boolean isLogin = this.isLogin(request);
		if (isLogin) {
			Model newModel = repositoryService.newModel();
			try {

				ObjectMapper objectMapper = new ObjectMapper();
				ObjectNode modelObjectNode = objectMapper.createObjectNode();
				modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME,
						activiti.getName());
				modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
				modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION,
						StringUtils.defaultString(activiti.getDescription()));
				newModel.setMetaInfo(modelObjectNode.toString());
				newModel.setName(activiti.getName());
				newModel.setKey(StringUtils.defaultString(activiti.getKey()));
				repositoryService.saveModel(newModel);
				ObjectNode editorNode = objectMapper.createObjectNode();
				editorNode.put("id", "canvas");
				editorNode.put("resourceId", "canvas");
				ObjectNode stencilSetNode = objectMapper.createObjectNode();
				stencilSetNode.put("namespace",
						"http://b3mn.org/stencilset/bpmn2.0#");
				editorNode.put("stencilset", stencilSetNode);
				repositoryService.addModelEditorSource(newModel.getId(),
						editorNode.toString().getBytes("utf-8"));
			} catch (Exception e) {
				e.getStackTrace();
			}
			// response.sendRedirect(request.getContextPath() +
			// "/service/editor?id="
			// + newModel.getId());
			map.put("isLogin", "yes");
			map.put("userName",
					(String) request.getSession().getAttribute("userName"));
			map.put("path", "/service/editor?id=");
			map.put("modelId", newModel.getId());
		} else {
			map.put("isLogin", "no");
		}
		return map;
	}


6.angular js前台代码,路由控制页面跳转:

  (1).app.js:

       

$stateProvider  
    .state('create', {  
    url: "/create",  
    views: {  
       'view': {  
        templateUrl: 'activi_views/create.html',  
        controller: 'createCtr'  
       }  
    }  
   });  

   (2).createCtr.js,angular js中的控制器,和后台交互,按我们公司前端现在的标准做法,应该还要服务层service,但是我运用还不太熟练,就暂且都放在controller中了:

 

angular.module('activitiApp')  
.controller('createCtr', ['$rootScope','$scope','$http','$location','$state', function($rootScope,$scope,$http,$location,$state){  
    //创建模型
	$http.post("createFlush.do").success(function(result){
		if(result.isLogin==="yes"){
			$rootScope.userName=result.userName;
		}else{
			$location.path("/login");
		}
	});
    $scope.createTo=function(activiti){
        //向后台提交数据
      $http.post("./create.do",activiti,{headers:'Content-Type:application/json'}).success(function(createResult){
    	  console.log(createResult);
    	  $location.path("/modelList");
    	window.open("http://localhost:8080/activitiTest1"+createResult.path+createResult.modelId);
      });

    }  
  
}])  

  (3).index.html:

<!DOCTYPE html>
<html ng-app="activitiApp">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link href="./activi_css/activi.css" rel="stylesheet"/> 
  <link href="css/bootstrap/css/bootstrap.css?2023" rel="stylesheet" type="text/css" />
  <link href="css/site.css?2023" rel="stylesheet" type="text/css" />
  <script type="text/javascript">
        var _root='http://form/index.php?s=/',_controller = 'index';
  </script>
  <script src="./angular-1.4.0-rc.2/angular.js"></script>
  <script src='./angular-1.4.0-rc.2/angular-ui-router.js'></script>
  <script src='./activi_js/app.js'></script>
  <script src='./activi_js/createCtr.js'></script>
  <script src='./activi_js/modelCtr.js'></script>
  <script src='./activi_js/processCtr.js'></script>
  <script src='./activi_js/taskCtr.js'></script>
  <script src='./activi_js/loginCtr.js'></script>
  <script src='./activi_js/hisTaskCtr.js'></script>
  <script src='./activi_js/startProcessCtr.js'></script>
  <script src='./activi_js/completeTaskCtr.js'></script>
</head>
<body style="width:100%;height:300px;margin:0;background-color:#fff">
 <div style="height:70px;width:100%;border:1px solid #ccf">
    <img id="rdiv" src="./images/activiti.png" style="width:30%;height:98%"/>
     <a href="script:;" ng-show="userName!=undefined" style="margin-right:10px;float:right;margin-top:25px;" ng-click="logOut();">
     [退出登陆]
    </a>
    <font ng-show="userName!=undefined" style="margin-right:10px;float:right;margin-top:25px;">当前登陆用户:{{userName}}</font>
 </div>
 <div style="width:100%;position: absolute;height:auto">
 <div style="height:580px;width:12%;font-size:36px;position:relative;float:left;border:1px solid #ccf" ng-show="userName!=undefined">
    <table style="width:100%;text-align:center;margin-top:0px" cellSpacing="5px" cellPadding="0px">
      <tr>
         <td style="background-color:#caf;"><a href="#/create">创建模型</a></td>
      </tr>
      <tr>
         <td style="background-color:#ccf;"> <a href="#/modelList">模型列表</a></td>
      </tr>
      <tr>
         <td style="background-color:#cef;"><a href="#/processList">流程列表</a></td>
      </tr>
      <tr>
         <td style="background-color:#aef;"><a href="#/taskList">当前任务</a></td>
      </tr>
       <tr>
         <td style="background-color:#fef;"><a href="#/hisTask">历史任务</a></td>
      </tr>
    </table>
 </div>
 
 <div ui-view="view" ></div>
 </div>
</body>
</html>
   

(4).create.html:

<center>  
<div style="margin-top:100px;margin-left:200px;background-color:#9cc;height:350px;width:40%;font-size:26px;position:relative;float:left;">  
    <p style="font-size:30px">创建模型</p>
    Name   :<input type="text" name="name" ng-model="activiti.name"/> 
    </br>  
    </br>  
    Key    :<input type="text" name="key" ng-model="activiti.key"/>  
    </br>  
    </br>  
    Description:<input type="text" name="description" ng-model="activiti.description"/>  
    </br>  
    </br>  
    <input style="font-size:28px;cursor:pointer" type="button" value="创建模型" ng-click="createTo(activiti);">  
           
    <input style="font-size:28px;cursor:pointer" type="button" value="返回">  
</div>  
</center>  

7.如果模型创建成功,则可以看到数据库act_re_model中会出现一条数据,如下:



同时在act_ge_bytearray表中会出现两条数据,如下图:


并且可以看到,在model表中会有两个字段把bytearray表中两条数据的id保存起来。

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
8天前
|
IDE Java 应用服务中间件
spring boot 启动流程
Spring Boot 启动流程简介: 在使用 Spring Boot 之前,启动 Java Web 应用需要配置 Web 容器(如 Tomcat),并将应用打包放入容器目录。而使用 Spring Boot,只需运行 main() 方法即可启动 Web 应用。Spring Boot 的核心启动方法是 SpringApplication.run(),它负责初始化和启动应用上下文。 主要步骤包括: 1. **应用启动计时**:使用 StopWatch 记录启动时间。 2. **打印 Banner**:显示 Spring Boot 的 LOGO。 3. **创建上下文实例**:通过反射创建
|
2月前
|
XML Java 数据格式
使用idea中的Live Templates自定义自动生成Spring所需的XML配置文件格式
本文介绍了在使用Spring框架时,如何通过创建`applicationContext.xml`配置文件来管理对象。首先,在resources目录下新建XML配置文件,并通过IDEA自动生成部分配置。为完善配置,特别是添加AOP支持,可以通过IDEA的Live Templates功能自定义XML模板。具体步骤包括:连续按两次Shift搜索Live Templates,配置模板内容,输入特定前缀(如spring)并按Tab键即可快速生成完整的Spring配置文件。这样可以大大提高开发效率,减少重复工作。
使用idea中的Live Templates自定义自动生成Spring所需的XML配置文件格式
|
2月前
|
设计模式 XML Java
【23种设计模式·全精解析 | 自定义Spring框架篇】Spring核心源码分析+自定义Spring的IOC功能,依赖注入功能
本文详细介绍了Spring框架的核心功能,并通过手写自定义Spring框架的方式,深入理解了Spring的IOC(控制反转)和DI(依赖注入)功能,并且学会实际运用设计模式到真实开发中。
【23种设计模式·全精解析 | 自定义Spring框架篇】Spring核心源码分析+自定义Spring的IOC功能,依赖注入功能
|
2月前
|
NoSQL Java Redis
Spring Boot 自动配置机制:从原理到自定义
Spring Boot 的自动配置机制通过 `spring.factories` 文件和 `@EnableAutoConfiguration` 注解,根据类路径中的依赖和条件注解自动配置所需的 Bean,大大简化了开发过程。本文深入探讨了自动配置的原理、条件化配置、自定义自动配置以及实际应用案例,帮助开发者更好地理解和利用这一强大特性。
153 14
|
3月前
|
安全 Java 应用服务中间件
如何将Spring Boot应用程序运行到自定义端口
如何将Spring Boot应用程序运行到自定义端口
114 0
|
4月前
|
JSON 前端开发 JavaScript
优雅!Spring Boot 3.3 实现职责链模式,轻松应对电商订单流程
本文介绍如何使用 Spring Boot 3.3 实现职责链模式,优化电商订单处理流程。通过将订单处理的各个环节(如库存校验、优惠券核验、支付处理等)封装为独立的处理器,并通过职责链将这些处理器串联起来,实现了代码的解耦和灵活扩展。具体实现包括订单请求类 `OrderRequest`、抽象处理器类 `OrderHandler`、具体处理器实现(如 `OrderValidationHandler`、`VerifyCouponHandler` 等)、以及初始化职责链的配置类 `OrderChainConfig`。
|
29天前
|
XML Java 应用服务中间件
Spring Boot 两种部署到服务器的方式
本文介绍了Spring Boot项目的两种部署方式:jar包和war包。Jar包方式使用内置Tomcat,只需配置JDK 1.8及以上环境,通过`nohup java -jar`命令后台运行,并开放服务器端口即可访问。War包则需将项目打包后放入外部Tomcat的webapps目录,修改启动类继承`SpringBootServletInitializer`并调整pom.xml中的打包类型为war,最后启动Tomcat访问应用。两者各有优劣,jar包更简单便捷,而war包适合传统部署场景。需要注意的是,war包部署时,内置Tomcat的端口配置不会生效。
233 17
Spring Boot 两种部署到服务器的方式
|
29天前
|
Dart 前端开发 JavaScript
springboot自动配置原理
Spring Boot 自动配置原理:通过 `@EnableAutoConfiguration` 开启自动配置,扫描 `META-INF/spring.factories` 下的配置类,省去手动编写配置文件。使用 `@ConditionalXXX` 注解判断配置类是否生效,导入对应的 starter 后自动配置生效。通过 `@EnableConfigurationProperties` 加载配置属性,默认值与配置文件中的值结合使用。总结来说,Spring Boot 通过这些机制简化了开发配置流程,提升了开发效率。
61 17
springboot自动配置原理
|
1月前
|
XML JavaScript Java
SpringBoot集成Shiro权限+Jwt认证
本文主要描述如何快速基于SpringBoot 2.5.X版本集成Shiro+JWT框架,让大家快速实现无状态登陆和接口权限认证主体框架,具体业务细节未实现,大家按照实际项目补充。
87 11
|
1月前
|
缓存 安全 Java
Spring Boot 3 集成 Spring Security + JWT
本文详细介绍了如何使用Spring Boot 3和Spring Security集成JWT,实现前后端分离的安全认证概述了从入门到引入数据库,再到使用JWT的完整流程。列举了项目中用到的关键依赖,如MyBatis-Plus、Hutool等。简要提及了系统配置表、部门表、字典表等表结构。使用Hutool-jwt工具类进行JWT校验。配置忽略路径、禁用CSRF、添加JWT校验过滤器等。实现登录接口,返回token等信息。
369 12