This action will force synchronization from 若依/RuoYi-Vue, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
本项目是在RuoYi开发框架中集成Nop平台的示例应用。后端基于RuoYi v3.8.5。
后端代码: nop-for-ruoyi 前端代码: nop-for-ruoyi-vue3
修改项目根目录下的pom文件,将nop平台的nop-spring-web-start模块和nop-sys-web模块和nop加入依赖管理
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-spring-web-starter</artifactId>
<version>${nop-entropy.version}</version>
</dependency>
<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-sys-web</artifactId>
<version>${nop-entropy.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
目前nop-entropy的包并没有上传maven中央仓库,所以编译app-mall项目之前需要先编译nop-entropy项目。
git clone https://gitee.com/canonical-entropy/nop-entropy.git
cd nop-entropy
mvn -T 2C clean install -DskipTests -Dquarkus.package.type=uber-jar
在ruoyi-admin模块中引入nop-spring-web-starter和nop-sys-web模块,其中nop-spring-web-starter模块是实现Springboot与Nop平台集成所必须的, 而引入nop-sys-web模块是为了使用NopSysSequence顺序号生成器表以及演示如何集成Nop平台生产的模块。
<dependencies>
<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-spring-web-starter</artifactId>
</dependency>
<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-sys-web</artifactId>
</dependency>
</dependencies>
在application.yaml中增加配置
nop:
debug: true
orm:
init-database-schema: true
这样会以调试模式启动,并自动根据ORM模型创建NopSysSequence等所需要的数据库表。
一般情况下基于Nop平台开发的模块并不依赖于Spring框架,可以独立开发并使用自动生成的xxx-app来测试,最后再在ruoyi工程中引入对应模块来打包为spring服务。
增加resources/_vfs/_delta/default/nop/dao/beans/dao-defaults.beans.xml
,通过可逆计算取消Nop平台内置的nopDataSource,并将Spring中的dynamicDataSource映射为nopDataSource。
<beans x:schema="/nop/schema/beans.xdef" xmlns:x="/nop/schema/xdsl.xdef"
x:extends="super" x:dump="true">
<bean id="nopDataSource" x:override="remove" />
<bean id="nopHikariConfig" x:override="remove" />
<alias name="dynamicDataSource" alias="nopDataSource" />
</beans>
在ruoyi-framework模块中引入nop-spring-web-starter依赖
<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-spring-web-starter</artifactId>
</dependency>
在JwtAuthenticationTokenFilter中增加登录后用户上下文的初始化代码
void initUserContext(LoginUser loginUser) {
UserContextImpl userContext = new UserContextImpl();
String userName = loginUser.getUsername();
userContext.setUserName(userName);
userContext.setUserId(loginUser.getUserId());
userContext.setDeptId(String.valueOf(loginUser.getDeptId()));
userContext.setAccessToken(loginUser.getToken());
userContext.setSessionId(loginUser.getToken());
IUserContext.set(userContext);
}
在ruoyi-framework模块中增加IActionAuthChecker的实现类
public class NopActionAuthChecker implements IActionAuthChecker {
@Inject
PermissionService permissionService;
@Override
public boolean isPermitted(String permission, IUserContext iUserContext) {
return permissionService.hasPermi(permission);
}
}
在定制的dao-defaults.beans.xml中增加配置
<bean id="actionAuthChecker" class="com.ruoyi.framework.web.service.PermissionService" />
Nop平台是在Spring框架初始化完毕之后创建的,因此在Nop平台开发的模块中可以通过 @Inject标准注解来直接注入Spring容器所管理的类。
而在Spring容器所创建的服务类中,不能自动注入Nop平台所管理的类,但是可以通过BeanContainer获取,例如
IGraphQLEngine engine = BeanContainer.instance().getBeanByType(IGraphQLEngine.class);
BeanContainer.instance().getBean("myBean");
建议使用Nop平台开发的时候,尽量不直接使用Spring相关的类,可以封装为接口后注入到模块中使用。通过这种方式,可以使得相应功能摆脱Spring依赖,未来可以移植到Quarkus框架中使用。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。