Local is not bound

本文解释了为何不应将EJB类接口直接放入Web应用的lib目录下,详细阐述了Web应用类装载器与EJB类装载器之间的交互过程,以及将EJB接口置于Web应用lib目录可能导致的类型冲突问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Local is not bound说这个Local没有边界。

实际上就是说它认为你并没是一个本地接口,

出现这个原因是因为我没有把那个HelloWorldBean这个类文件导入进去。

为什么我们不用将EJB的类接口放入到Web应用的lib下面呢?

因为加载Web应用的类装载器时,如果没有寻找到这个接口时候它会交给EJB的类装载器进行处理。

而EJB应用已经加载到了WEB应用中了,所以这个就可以加载上了。

如果把EJB接口放在了WEB应用户的lib 下面的时候那么在有些情况下还会造成类型冲突的情况。

The import statement import_stmt ::= "import" module ["as" name] ( "," module ["as" name] )* | "from" relative_module "import" identifier ["as" name] ( "," identifier ["as" name] )* | "from" relative_module "import" "(" identifier ["as" name] ( "," identifier ["as" name] )* [","] ")" | "from" module "import" "*" module ::= (identifier ".")* identifier relative_module ::= "."* module | "."+ name ::= identifier The basic import statement (no from clause) is executed in two steps: find a module, loading and initializing it if necessary define a name or names in the local namespace for the scope where the import statement occurs. When the statement contains multiple clauses (separated by commas) the two steps are carried out separately for each clause, just as though the clauses had been separated out into individiual import statements. The details of the first step, finding and loading modules are described in greater detail in the section on the import system, which also describes the various types of packages and modules that can be imported, as well as all the hooks that can be used to customize the import system. Note that failures in this step may indicate either that the module could not be located, or that an error occurred while initializing the module, which includes execution of the module’s code. If the requested module is retrieved successfully, it will be made available in the local namespace in one of three ways: If the module name is followed by as, then the name following as is bound directly to the imported module. If no other name is specified, and the module being imported is a top level module, the module’s name is bound in the local namespace as a reference to the imported module If the module being imported is not a top level module, then the name of the top level package that contains the module is bound in the local namespace as a reference to the top level package. The imported module must be accessed using its full qualified name rather than directly The from form uses a slightly more complex process: find the module specified in the from clause, loading and initializing it if necessary; for each of the identifiers specified in the import clauses: check if the imported module has an attribute by that name if not, attempt to import a submodule with that name and then check the imported module again for that attribute if the attribute is not found, ImportError is raised. otherwise, a reference to that value is stored in the local namespace, using the name in the as clause if it is present, otherwise using the attribute name Examples: import foo # foo imported and bound locally import foo.bar.baz # foo.bar.baz imported, foo bound locally import foo.bar.baz as fbb # foo.bar.baz imported and bound as fbb from foo.bar import baz # foo.bar.baz imported and bound as baz from foo import attr # foo imported and foo.attr bound as attr If the list of identifiers is replaced by a star ('*'), all public names defined in the module are bound in the local namespace for the scope where the import statement occurs. The public names defined by a module are determined by checking the module’s namespace for a variable named __all__; if defined, it must be a sequence of strings which are names defined or imported by that module. The names given in __all__ are all considered public and are required to exist. If __all__ is not defined, the set of public names includes all names found in the module’s namespace which do not begin with an underscore character ('_'). __all__ should contain the entire public API. It is intended to avoid accidentally exporting items that are not part of the API (such as library modules which were imported and used within the module). The wild card form of import — from module import * — is only allowed at the module level. Attempting to use it in class or function definitions will raise a SyntaxError. When specifying what module to import you do not have to specify the absolute name of the module. When a module or package is contained within another package it is possible to make a relative import within the same top package without having to mention the package name. By using leading dots in the specified module or package after from you can specify how high to traverse up the current package hierarchy without specifying exact names. One leading dot means the current package where the module making the import exists. Two dots means up one package level. Three dots is up two levels, etc. So if you execute from . import mod from a module in the pkg package then you will end up importing pkg.mod. If you execute from ..subpkg2 import mod from within pkg.subpkg1 you will import pkg.subpkg2.mod. The specification for relative imports is contained within PEP 328 . importlib.import_module() is provided to support applications that determine dynamically the modules to be loaded.
最新发布
05-30
``` import torch import torch.nn as nn import torch.optim as optim import numpy as np class Client: def __init__(self, model, dataset, learning_rate=0.01, local_epochs=5, noise_scale=1.0, clip_bound=1.0): """ 初始化客户端 Args: model: 神经网络模型 dataset: 本地数据集 learning_rate: 学习率 local_epochs: 本地训练轮数 noise_scale: 差分隐私噪声规模 clip_bound: 梯度裁剪界限 """ self.model = model self.dataset = dataset self.learning_rate = learning_rate self.local_epochs = local_epochs self.noise_scale = noise_scale self.clip_bound = clip_bound self.optimizer = optim.SGD(self.model.parameters(), lr=learning_rate) self.criterion = nn.CrossEntropyLoss() def add_noise(self, gradients): """ 添加高斯噪声实现差分隐私 Args: gradients: 模型梯度 Returns: 添加噪声后的梯度 """ noisy_gradients = [] for grad in gradients: if grad is not None: noise = torch.normal(mean=0, std=self.noise_scale, size=grad.shape) noisy_gradients.append(grad + noise) else: noisy_gradients.append(None) return noisy_gradients def clip_gradients(self, gradients): """ 梯度裁剪 Args: gradients: 模型梯度 Returns: 裁剪后的梯度 """ total_norm = 0 for grad in gradients: if grad is not None: total_norm += grad.norm(2).item() ** 2 total_norm = total_norm ** 0.5 clip_coef = self.clip_bound / (total_norm + 1e-6) if clip_coef < 1: for grad in gradients: if grad is not None: grad.mul_(clip_coef) return gradients def train(self, dataloader): """ 本地训练 Args: dataloader: 数据加载器 Returns: 更新后的模型参数 """ self.model.train() for _ in range(self.local_epochs): for data, target in dataloader: self.optimizer.zero_grad() output = self.model(data) loss = self.criterion(output, target) loss.backward() # 获取梯度 gradients = [param.grad.clone() for param in self.model.parameters()] # 梯度裁剪 clipped_gradients = self.clip_gradients(gradients) # 添加差分隐私噪声 noisy_gradients = self.add_noise(clipped_gradients) # 更新模型参数 for param, grad in zip(self.model.parameters(), noisy_gradients): if grad is not None: param.grad = grad self.optimizer.step() return [param.data.clone() for param in self.model.parameters()]```分析解释代码
03-11
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值