gpt4 book ai didi

Grails 3.3.8 - 如何从服务获取 session

转载 作者:行者123 更新时间:2023-12-02 14:39:09 25 4
gpt4 key购买 nike

好的,我有一个多模块项目,插件中包含服务,以及使用它的多个网络“应用程序”。

用户和播放器服务有一个登录和注册方法,需要通过更新 session 来“登录”播放器。

这篇文章:Grails get Session and Management in Service class

有一些解决方案,但实际上似乎都没有。 Webutils 在这些位置都不可用

import org.codehaus.groovy.grails.web.util.WebUtils
import org.grails.web.util.WebUtil
import org.grails.web.util.WebUtils

这也不起作用:
def session = getSession(true)

有什么建议么?

这是来自插件的 build.gradle:
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.5.Final"
compile "org.grails.plugins:scaffolding"
console "org.grails:grails-console"
profile "org.grails.profiles:plugin"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails:grails-plugin-testing"
}

最佳答案

Any suggestions?



是的。

你可以这样做:
// grails-app/services/somepackage/SomeService.groovy
package somepackage

import grails.web.api.ServletAttributes

class SomeService implements ServletAttributes {

void someMethod() {
// you can access the session property directly from here
println session

// ...
}
}

关于Grails 3.3.8 - 如何从服务获取 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56527074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com