我正在使用Nashorn javascript引擎来评估在java应用程序中编写的所有服务器端javascript代码.为了提高性能,我在启动时使用spring初始化JsEngine并评估和缓存所有核心工具,如Mustache和一些常见的JS工具.然后每次屏幕渲染时,这个预先评估的JsEngine将用于评估特定于页面的JavaScript代码.它在某些时候工作正常,意味着它按预期呈现页面,但在我持续点击相同的URL时开始抛出异常
我无法找到问题的根本原因.
@Component
public class JsEngine {
private ScriptEngine scriptEngine;
@PostConstruct
public void init() throws ScriptException, IOException{
scriptEngine = new ScriptEngineManager().getEngineByName("nashorn");
this.cacheAllCoreEngines();
for(String key: defaultEngineSource.keySet()){
scriptEngine.eval(defaultEngineSource.get(key));
}
}
private void cacheAllCoreEngines()throws IOException{
//read all core files such as mustache, etc.
defaultEngineSource.put("mustache", FileUtil.readFileFromDisk("<actual path..>/mustache.js"));
}
public Object eval(String source) throws ScriptException{
.... code to handle exceptions
return scriptEngine.eval (source);
}
}
Run Code Online (Sandbox Code Playgroud)
JsEngine如下所示,
public class AppRendererImpl implements AppRenderer {
@Autowired
JsEngine jsEngine;
public String render(){
....
.... //Read source from disk …
Run Code Online (Sandbox Code Playgroud) 我想知道的是" Spring bean中的所有类/方法都注释为@Versioned".
我创建了自定义注释,
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Versioned {
.....
}
Run Code Online (Sandbox Code Playgroud)
当我使用Java反射来查找方法时,此注释非常有效:
for(Method m: obj.getClass().getMethods()){
if(m.isAnnotationPresent(Versioned.class)){
.... // Do something
}
Run Code Online (Sandbox Code Playgroud)
但是当我访问Spring bean并尝试类似的检查时,它不起作用:
public class VersionScanner implements ApplicationContextAware{
public void setApplicationContext(ApplicationContext applicationContext){
for(String beanName: applicationContext.getBeanDefinitionNames()){
for(Method m: applicationContext.getBean(beanName).getClass().getDeclaredMethods()){
if(m.isAnnotationPresent(Versioned.class){
// This is not WORKING as expected for any beans with method annotated
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
实际上,此代码确实找到了其他注释,例如@RequestMapping.我不确定自定义注释我做错了什么.
我们有多个资源作为REST服务公开,并运行设计参数,如果服务因网络和/或应用程序级别故障而不可用,客户端是否需要实现重试逻辑.这值得么?一组认为,如果服务不可用,则没有重新尝试的点,但其他组织认为可能存在网络繁忙问题并且重试可能会有所帮助.目前没有统计数据可以为这两个论点辩护.如何实现回退URL(原始http资源的副本)并在失败期间使用回退服务.
根据您以前的经验提出任何建议吗?
在spring框架中,如果我将一个bean定义为范围"protoype"并且它是另一个bean的父级.子bean会自动成为原型吗?
例:
<bean id="a" class="..." scope="prototype"/>
<bean id="b" class="..." parent="a"/>
Run Code Online (Sandbox Code Playgroud)
b的范围是什么?
我曾参与过相当多使用 JAX-WS 实现的 Web 服务项目,例如 Axis。工件是使用 IDE 生成的,并且它可以工作。但是,我想知道生成的客户端工件以及它们的作用。如果您能提供任何明确的指南或来源,将会很有帮助。
我知道如何生成工件。但找不到任何描述生成的客户端工件及其用途的来源。
我将spring boot升级到最新版本1.2.0.RELEASE,现在最终出现以下异常.
used by: org.springframework.beans.NotWritablePropertyException: Invalid property 'text[encryption]' of bean class [org.springframework.boot.autoconfigure.security.SecurityProperties]: Cannot access indexed value in property referenced in indexed property path 'text[encryption]'; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'text[encryption]' of bean class [org.springframework.boot.autoconfigure.security.SecurityProperties]: Bean property 'text[encryption]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:950)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:926)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:749)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:645)
at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:119)
at org.springframework.validation.DataBinder.bind(DataBinder.java:630)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:251)
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:225)
at …
Run Code Online (Sandbox Code Playgroud) java ×6
spring ×4
.net ×1
algorithm ×1
java-8 ×1
jax-ws ×1
nashorn ×1
rest ×1
soa ×1
soap ×1
spring-boot ×1
spring-mvc ×1
web-services ×1