我想用Eclipse Scout实现数据库认证。Eclipse Scout - 干净的数据库认证
为此,我在客户端模块中创建了一个类DataSourceCredentialVerifier
,该模块实现了ICredentialVerifier
接口。然后我改编UiServletFilter
类的init
方法来使用我的验证器。
public class DataSourceCredentialVerifier implements ICredentialVerifier {
private static final Logger LOG = LoggerFactory.getLogger(DataSourceCredentialVerifier.class);
@Override
public int verify(String username, char[] password) throws IOException {
Object queryResult[][] = BEANS.get(IMySqlAuthService.class).load();
return AUTH_OK;
}
我还没有实现任何验证逻辑。我现在的任务是建立一个干净的数据库连接。
对于我创造了以下interface
共享模块:
public interface IMySqlAuthService extends IService {
Object[][] load();
}
的实施是服务器模块:
public class MySqlAuthService implements IMySqlAuthService {
@Override
public Object[][] load() {
String sql = "select username, password from users ";
Object[][] queryResult = SQL.select(sql, null, null);
return queryResult;
}
}
首先,我想看看,如果有至少是查询中的某些内容,但我在此处得到AssertionException:
Object queryResult[][] = BEANS.get(IMySqlAuthService.class).load();
org.eclipse.scout.rt.platform.util.Assertions$AssertionException: Assertion error: no instance found for query: interface org.eclipse.scout.app.shared.services.IMySqlAuthService
at org.eclipse.scout.rt.platform.util.Assertions.fail(Assertions.java:580)
at org.eclipse.scout.rt.platform.util.Assertions.assertNotNull(Assertions.java:87)
at org.eclipse.scout.rt.platform.BEANS.get(BEANS.java:41)
我没有得到我的MySqlAuthService
实现的实例。我认为BeanManager
应该为我创建了一个实例。 MySqlAuthService
应该注册为Bean,因为我的IMySqlAuthService
接口从IService
延伸,其中有@ApplicationScoped
注释。
将@Bean
注释添加到MySqlAuthService
导致相同的例外。
这里对BeanManager
和注释的一些信息: https://eclipsescout.github.io/6.0/technical-guide.html#sec-bean.manager
这里是另一种不同的方法S.O.尝试,但它不正确: https://www.eclipse.org/forums/index.php/t/1079741/
我怎样才能让我的例子与我的服务一起工作?