以下の技術スタックを使用してアプリケーションを開発しました。
Struts 2.1
Springs 3.1
Groovy 1.8
Tomcat 6.0.26 - For deployment
私たちの要件は、アプリケーションの特定のレイヤーを Groovy に移行することです。そのレイヤーを groovy に移行し、アプリケーションは正常に動作しています。移行後、Groovy Bean は Spring コンテナーによって適切に初期化されますが、Groovy の「動的言語」機能を利用できません。つまり、Groovy スクリプトを変更すると、更新された変更がアプリケーションに動的に反映されません。
参考までに、groovy スクリプト (GroovyConnection.groovy) のメソッドを添付します。
@Component
class GroovyConnection implements EndPointManager, Serializable{
private static final long serialVersionUID = 1481681752777429674L;
private final static Logger log = Logger.getLogger(GroovyConnection.class);
private static final String DESTINATION_DIR = ARTIFACT_DIR_PATH.toString()+"/";
private static final String JIVE_USER = ""; //"jivescpt";
/**
* @param default
*/
public GroovyConnection() {
super();
jschInstance = new JSch();
}
public String executeCommands(Session session, String inputCommand, Device device) {
log.info("Entering executeCommand() device:" + inputCommand);
Channel channel = null;
PipedOutputStream commandIO = null;
InputStream sessionInput = null;
InputStream sessionOutput = null;
InputStream sessionError = null;
String commandResponse = null;
try {
channel = session.openChannel("shell");
commandIO = new PipedOutputStream();
sessionInput = new PipedInputStream(commandIO);
channel.setInputStream(sessionInput);
sessionOutput = channel.getInputStream();
sessionError = channel.getExtInputStream();
channel.connect();
return fireCommandsOnTerminal(session, commandIO, sessionOutput, sessionError, inputCommand, device);
}
catch (JSchException e) {
log.error(AutomationConstants.ERROR_MSG.toString(), e);
}
catch (IOException e) {
log.error(AutomationConstants.ERROR_MSG.toString(), e);
}
catch (InterruptedException e) {
log.error(AutomationConstants.ERROR_MSG.toString(), e);
}
finally {
boolean isClosed = GroovyConnectionHelper.closeAll(session, channel, commandIO, sessionInput, sessionOutput, sessionError);
if (!isClosed) {
return AutomationUtils.getPropertyValue("jive.vpn.error.msg");
}
}
log.info("Exiting executeCommand() device:" + inputCommand);
return commandResponse;
}
}
Groovy コンテキスト ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">
<lang:defaults refresh-check-delay="2000"/>
<lang:groovy id="endPointManager"
script-source="classpath:GroovyConnection.groovy" refresh-check-delay="1000">
</lang:groovy>
</beans>
1 秒間の更新チェック遅延時間を指定した後でも、Groovy Bean は実行時に適切に動作しません。更新された Groovy の変更を再デプロイするには、Tomcat を再起動する必要があります。Groovy Bean を Java Bean として扱うアプリケーションのように見えます。
これとは別に、Springs を使用せずに groovy スクリプトを実行すると、期待どおりに実行されます。修正された groovy スクリプトの変更は、動的に反映されます。参照用のコードは次のとおりです。
グルーヴィーなスクリプト:
package com
public class test1 {
def hello_world() {
println "Connectddded"
}
}
メインクラス:
public static void main(String arg[]) {
try {
new GroovyShell().parse(newFile("test1.groovy")).invokeMethod("hello_world", null);
} catch (CompilationFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
私の理解によると、Groovy Bean の変更をリフレッシュできる Spring-Groovy Integration 構成の何かが欠けているか、Tomcat が更新された Groovy スクリプトをリフレッシュすることを許可していません。
誰かがこれに関する提案を提供できる場合は役に立ちます。前もって感謝します。
よろしく、 Divya Garg