diff --git a/pom.xml b/pom.xml
index 6624686..aeac1ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
com.github.answerail
dinger-spring-boot-starter
jar
- 1.2.0-beta1
+ 1.2.0-beta2
dinger-spring-boot-starter
Dinger-SpringBoot集成钉钉/企业微信群机器人实现消息通知中间件
diff --git a/src/main/java/com/github/jaemon/dinger/config/DingerAutoConfiguration.java b/src/main/java/com/github/jaemon/dinger/config/DingerAutoConfiguration.java
new file mode 100644
index 0000000..c2c5d1d
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/config/DingerAutoConfiguration.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.config;
+
+import com.github.jaemon.dinger.core.DingerRobot;
+import com.github.jaemon.dinger.core.entity.DingerProperties;
+import com.github.jaemon.dinger.core.session.DingerSessionFactory;
+import com.github.jaemon.dinger.core.spring.DingerSessionFactoryBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
+
+/**
+ * DingerAutoConfiguration
+ *
+ * @author Jaemon
+ * @since 1.2
+ */
+@Configuration
+@EnableConfigurationProperties(DingerProperties.class)
+@AutoConfigureAfter(DingerConfiguration.class)
+public class DingerAutoConfiguration implements InitializingBean {
+ private final DingerProperties properties;
+ private final DingerRobot dingerRobot;
+ private final ResourceLoader resourceLoader;
+
+ public DingerAutoConfiguration(
+ DingerProperties dingerProperties,
+ DingerRobot dingerRobot,
+ ResourceLoader resourceLoader
+ ) {
+ this.properties = dingerProperties;
+ this.dingerRobot = dingerRobot;
+ this.resourceLoader = resourceLoader;
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ public DingerSessionFactory dingerSessionFactory() throws Exception {
+ DingerSessionFactoryBean factory = new DingerSessionFactoryBean();
+
+ factory.setConfiguration(
+ com.github.jaemon.dinger.core.session.Configuration.of(properties, dingerRobot)
+ );
+
+ return factory.getObject();
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ checkConfigFileExists();
+ }
+
+ private void checkConfigFileExists() {
+
+ if (
+ StringUtils.hasText(this.properties.getDingerLocations())
+ ) {
+
+ Resource resource = this.resourceLoader.getResource(this.properties.getDingerLocations());
+
+ Assert.state(resource.exists(), "Cannot find config location: " + resource
+ + " (please add config file or check your Dinger configuration)");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java b/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java
index 41b3a4d..7f5155b 100644
--- a/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java
+++ b/src/main/java/com/github/jaemon/dinger/core/DingerHandleProxy.java
@@ -16,15 +16,14 @@
package com.github.jaemon.dinger.core;
import com.github.jaemon.dinger.core.annatations.DingerClose;
-import com.github.jaemon.dinger.core.entity.DingerProperties;
import com.github.jaemon.dinger.core.entity.MsgType;
import com.github.jaemon.dinger.core.entity.enums.DingerResponseCodeEnum;
import com.github.jaemon.dinger.core.entity.enums.DingerType;
import com.github.jaemon.dinger.core.entity.DingerResponse;
+import com.github.jaemon.dinger.core.session.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.*;
@@ -36,36 +35,40 @@
* @author Jaemon
* @since 1.0
*/
-public class DingerHandleProxy extends DingerMessageHandler implements InvocationHandler {
+public class DingerHandleProxy extends DingerInvocationHandler {
private static final Logger log = LoggerFactory.getLogger(DingerHandleProxy.class);
- private static final String DEFAULT_STRING_METHOD = "java.lang.Object.toString";
- public DingerHandleProxy(DingerRobot dingerRobot, DingerProperties dingerProperties) {
- this.dingerRobot = dingerRobot;
- this.dingerProperties = dingerProperties;
+ public DingerHandleProxy(Configuration configuration) {
+ this.dingerRobot = configuration.getDingerRobot();
+ this.dingerProperties = configuration.getDingerProperties();
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Class> dingerClass = method.getDeclaringClass();
- boolean clzClose = dingerClass.isAnnotationPresent(DingerClose.class);
- if (clzClose) {
+
+ final String methodName = method.getName();
+
+ if (
+ ignoreMethodMap.containsKey(methodName)
+ ) {
+ return ignoreMethodMap.get(methodName).execute(this, args);
+ }
+
+ if (
+ dingerClass.isAnnotationPresent(DingerClose.class)
+ ) {
return null;
}
- boolean methodClose = method.isAnnotationPresent(DingerClose.class);
- if (methodClose) {
+ if (
+ method.isAnnotationPresent(DingerClose.class)
+ ) {
return null;
}
final String dingerClassName = dingerClass.getName();
- final String methodName = method.getName();
String keyName = dingerClassName + SPOT_SEPERATOR + methodName;
-
- if (DEFAULT_STRING_METHOD.equals(keyName)) {
- return this.toString();
- }
-
try {
DingerType useDinger = dingerType(method);
DingerDefinition dingerDefinition = dingerDefinition(
@@ -73,6 +76,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
);
DingerResponse dingerResponse;
+
if (dingerDefinition == null) {
dingerResponse = DingerResponse.failed(
DingerResponseCodeEnum.MESSAGE_TYPE_UNSUPPORTED,
diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerInvocationHandler.java b/src/main/java/com/github/jaemon/dinger/core/DingerInvocationHandler.java
new file mode 100644
index 0000000..a461e3e
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/DingerInvocationHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core;
+
+import java.lang.reflect.InvocationHandler;
+
+/**
+ * Dinger Invocation Handler
+ *
+ * @author Jaemon
+ * @since 1.2
+ */
+public abstract class DingerInvocationHandler
+ extends DingerMessageHandler
+ implements InvocationHandler {
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/entity/enums/IgnoreMethod.java b/src/main/java/com/github/jaemon/dinger/core/entity/enums/IgnoreMethod.java
new file mode 100644
index 0000000..5ec46f8
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/entity/enums/IgnoreMethod.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.entity.enums;
+
+import com.github.jaemon.dinger.core.DingerInvocationHandler;
+
+/**
+ * Ignore Method
+ *
+ * @author Jaemon
+ * @since 1.2
+ */
+public enum IgnoreMethod {
+
+ EQUALS("equals") {
+ @Override
+ public Boolean execute(DingerInvocationHandler invocationHandler, Object[] args) {
+ return invocationHandler.equals(args[0]);
+ }
+ },
+ CLONE("clone") {
+ @Override
+ public Object execute(DingerInvocationHandler invocationHandler, Object[] args) throws CloneNotSupportedException {
+ return invocationHandler.clone();
+ }
+ },
+ HASH_CODE("hashCode") {
+ @Override
+ public Integer execute(DingerInvocationHandler invocationHandler, Object[] args) throws Exception {
+ return invocationHandler.hashCode();
+ }
+ },
+ TO_STRING("toString") {
+ @Override
+ public String execute(DingerInvocationHandler invocationHandler, Object[] args) throws Exception {
+ return invocationHandler.toString();
+ }
+ },
+
+ ;
+
+ private String methodName;
+
+ IgnoreMethod(String methodName) {
+ this.methodName = methodName;
+ }
+
+
+ public abstract Object execute(DingerInvocationHandler invocationHandler, Object[] args) throws Exception;
+
+ public String getMethodName() {
+ return methodName;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/session/Configuration.java b/src/main/java/com/github/jaemon/dinger/core/session/Configuration.java
new file mode 100644
index 0000000..2f9a008
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/session/Configuration.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.session;
+
+import com.github.jaemon.dinger.core.DingerRobot;
+import com.github.jaemon.dinger.core.entity.DingerProperties;
+
+/**
+ * Configuration
+ *
+ * @author Jaemon
+ * @version 1.2
+ */
+public class Configuration {
+ protected DingerProperties dingerProperties;
+ protected DingerRobot dingerRobot;
+
+ private Configuration(DingerProperties dingerProperties, DingerRobot dingerRobot) {
+ this.dingerProperties = dingerProperties;
+ this.dingerRobot = dingerRobot;
+ }
+
+ public static Configuration of(DingerProperties dingerProperties, DingerRobot dingerRobot) {
+ return new Configuration(dingerProperties, dingerRobot);
+ }
+
+ public DingerProperties getDingerProperties() {
+ return dingerProperties;
+ }
+
+ public DingerRobot getDingerRobot() {
+ return dingerRobot;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/session/DingerSession.java b/src/main/java/com/github/jaemon/dinger/core/session/DingerSession.java
new file mode 100644
index 0000000..f081b49
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/session/DingerSession.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.session;
+
+
+/**
+ * DingerSession
+ *
+ * @author Jaemon
+ * @since 1.0
+ */
+public interface DingerSession {
+
+ /**
+ * Retrieves a dinger.
+ *
+ * @param type
+ * dinger interface class
+ * @param
+ * the dinger type
+ * @return
+ * a dinger bound to this DingerSession
+ */
+ T getDinger(Class type);
+
+ /**
+ * dinger configuration
+ *
+ * @return
+ * {@link Configuration}
+ */
+ Configuration configuration();
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/session/DingerSessionFactory.java b/src/main/java/com/github/jaemon/dinger/core/session/DingerSessionFactory.java
new file mode 100644
index 0000000..7ff2aaf
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/session/DingerSessionFactory.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.session;
+
+/**
+ * DingerSessionFactory
+ *
+ * @author Jaemon
+ * @version 1.2
+ */
+public interface DingerSessionFactory {
+
+ /**
+ * dinger session
+ *
+ * @return
+ * {@link DingerSession}
+ */
+ DingerSession dingerSession();
+
+ /**
+ * dinger configuration
+ *
+ * @return
+ * {@link Configuration}
+ */
+ Configuration getConfiguration();
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/DingerSession.java b/src/main/java/com/github/jaemon/dinger/core/session/defaults/DefaultDingerSession.java
similarity index 58%
rename from src/main/java/com/github/jaemon/dinger/core/DingerSession.java
rename to src/main/java/com/github/jaemon/dinger/core/session/defaults/DefaultDingerSession.java
index 7db6a08..50d7c0e 100644
--- a/src/main/java/com/github/jaemon/dinger/core/DingerSession.java
+++ b/src/main/java/com/github/jaemon/dinger/core/session/defaults/DefaultDingerSession.java
@@ -13,34 +13,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.github.jaemon.dinger.core;
+package com.github.jaemon.dinger.core.session.defaults;
-import com.github.jaemon.dinger.core.entity.DingerProperties;
+import com.github.jaemon.dinger.core.DingerHandleProxy;
+import com.github.jaemon.dinger.core.session.Configuration;
+import com.github.jaemon.dinger.core.session.DingerSession;
import java.lang.reflect.Proxy;
/**
- * DingerSession
+ * DefaultDingerSession
*
* @author Jaemon
- * @since 1.0
+ * @version 1.2
*/
-public class DingerSession {
- private DingerRobot dingerRobot;
- private DingerProperties dingerProperties;
+public class DefaultDingerSession implements DingerSession {
- public DingerSession(DingerRobot dingerRobot, DingerProperties dingerProperties) {
- this.dingerRobot = dingerRobot;
- this.dingerProperties = dingerProperties;
+ private final Configuration configuration;
+
+ public DefaultDingerSession(Configuration configuration) {
+ this.configuration = configuration;
}
+ @Override
public T getDinger(Class type) {
return (T) Proxy.newProxyInstance(
// bugfix gitee#I29N15
Thread.currentThread().getContextClassLoader(),
new Class[]{type},
- new DingerHandleProxy(dingerRobot, dingerProperties)
+ new DingerHandleProxy(configuration())
);
}
+ @Override
+ public Configuration configuration() {
+ return configuration;
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/session/defaults/DefaultDingerSessionFactory.java b/src/main/java/com/github/jaemon/dinger/core/session/defaults/DefaultDingerSessionFactory.java
new file mode 100644
index 0000000..8b1eabd
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/session/defaults/DefaultDingerSessionFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.session.defaults;
+
+import com.github.jaemon.dinger.core.session.Configuration;
+import com.github.jaemon.dinger.core.session.DingerSession;
+import com.github.jaemon.dinger.core.session.DingerSessionFactory;
+
+/**
+ * DefaultDingerSessionFactory
+ *
+ * @author Jaemon
+ * @version 1.2
+ */
+public class DefaultDingerSessionFactory implements DingerSessionFactory {
+ private Configuration configuration;
+
+ public DefaultDingerSessionFactory(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Override
+ public DingerSession dingerSession() {
+ return new DefaultDingerSession(configuration);
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return this.configuration;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java b/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java
index 7e11ce9..bf791bb 100644
--- a/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java
+++ b/src/main/java/com/github/jaemon/dinger/core/spring/DingerFactoryBean.java
@@ -15,6 +15,7 @@
*/
package com.github.jaemon.dinger.core.spring;
+import com.github.jaemon.dinger.core.spring.support.DingerSessionSupport;
import org.springframework.beans.factory.FactoryBean;
/**
diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionFactoryBean.java b/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionFactoryBean.java
new file mode 100644
index 0000000..8cee8f8
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionFactoryBean.java
@@ -0,0 +1,52 @@
+package com.github.jaemon.dinger.core.spring;
+
+import com.github.jaemon.dinger.core.session.Configuration;
+import com.github.jaemon.dinger.core.session.DingerSessionFactory;
+import com.github.jaemon.dinger.core.session.defaults.DefaultDingerSessionFactory;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
+
+import java.io.IOException;
+
+/**
+ * DingerSessionFactoryBean
+ *
+ * @author Jaemon
+ * @version 1.2
+ */
+public class DingerSessionFactoryBean implements FactoryBean, InitializingBean {
+ private DingerSessionFactory dingerSessionFactory;
+ private Configuration configuration;
+
+ @Override
+ public DingerSessionFactory getObject() throws Exception {
+ if (this.dingerSessionFactory == null) {
+ afterPropertiesSet();
+ }
+ return dingerSessionFactory;
+ }
+
+ @Override
+ public Class> getObjectType() {
+ return this.dingerSessionFactory == null ? DingerSessionFactory.class : this.dingerSessionFactory.getClass();
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ this.dingerSessionFactory = buildDingerSessionFactory();
+ }
+
+
+ protected DingerSessionFactory buildDingerSessionFactory() throws IOException {
+ return new DefaultDingerSessionFactory(configuration);
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionSupport.java b/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionSupport.java
deleted file mode 100644
index a9f1505..0000000
--- a/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionSupport.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright ©2015-2021 Jaemon. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.jaemon.dinger.core.spring;
-
-import com.github.jaemon.dinger.core.DingerRobot;
-import com.github.jaemon.dinger.core.DingerSession;
-import com.github.jaemon.dinger.core.entity.DingerProperties;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- * DingerSessionSupport
- *
- * @author Jaemon
- * @version 1.2
- */
-public abstract class DingerSessionSupport implements InitializingBean {
- protected DingerSession dingerSession;
-
- @Autowired
- private DingerRobot dingerRobot;
- @Autowired
- private DingerProperties dingerProperties;
-
- public void setDingerSession() {
- if (dingerSession == null) {
- this.dingerSession = new DingerSession(dingerRobot, dingerProperties);
- }
- }
-
- public DingerSession getDingerSession() {
- return this.dingerSession;
- }
-
- @Override
- public void afterPropertiesSet() throws Exception {
- setDingerSession();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionTemplate.java b/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionTemplate.java
new file mode 100644
index 0000000..d6c2370
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/spring/DingerSessionTemplate.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.spring;
+
+import com.github.jaemon.dinger.core.session.Configuration;
+import com.github.jaemon.dinger.core.session.DingerSession;
+import com.github.jaemon.dinger.core.session.DingerSessionFactory;
+import org.springframework.beans.factory.DisposableBean;
+
+/**
+ * DingerSessionTemplate
+ *
+ * @author Jaemon
+ * @version 1.2
+ */
+public class DingerSessionTemplate implements DingerSession, DisposableBean {
+ private final DingerSessionFactory dingerSessionFactory;
+ private final DingerSession dingerSession;
+ private final Configuration configuration;
+
+ public DingerSessionTemplate(DingerSessionFactory dingerSessionFactory) {
+ this.dingerSessionFactory = dingerSessionFactory;
+ this.dingerSession = dingerSessionFactory.dingerSession();
+ this.configuration = dingerSessionFactory.getConfiguration();
+ }
+
+ @Override
+ public T getDinger(Class type) {
+ return dingerSession.getDinger(type);
+ }
+
+ @Override
+ public Configuration configuration() {
+ return configuration;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+
+
+ public DingerSessionFactory getDingerSessionFactory() {
+ return dingerSessionFactory;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/core/spring/support/DingerSessionSupport.java b/src/main/java/com/github/jaemon/dinger/core/spring/support/DingerSessionSupport.java
new file mode 100644
index 0000000..e451c81
--- /dev/null
+++ b/src/main/java/com/github/jaemon/dinger/core/spring/support/DingerSessionSupport.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright ©2015-2021 Jaemon. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jaemon.dinger.core.spring.support;
+
+import com.github.jaemon.dinger.core.session.DingerSession;
+import com.github.jaemon.dinger.core.session.DingerSessionFactory;
+import com.github.jaemon.dinger.core.spring.DingerSessionTemplate;
+
+/**
+ * DingerSessionSupport
+ *
+ * @author Jaemon
+ * @version 1.2
+ */
+public abstract class DingerSessionSupport {
+ private DingerSessionTemplate dingerSessionTemplate;
+
+ public void setDingerSessionFactory(DingerSessionFactory dingerSessionFactory) {
+
+ if (
+ dingerSessionTemplate == null ||
+ dingerSessionFactory != this.dingerSessionTemplate.getDingerSessionFactory()
+ ) {
+ this.dingerSessionTemplate = createDingerSessionTemplate(dingerSessionFactory);
+ }
+
+ }
+
+ public DingerSession getDingerSession() {
+ return this.dingerSessionTemplate;
+ }
+
+
+ protected DingerSessionTemplate createDingerSessionTemplate(DingerSessionFactory dingerSessionFactory) {
+ return new DingerSessionTemplate(dingerSessionFactory);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java
index f0db089..1c3a960 100644
--- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java
+++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerProperty.java
@@ -15,6 +15,11 @@
*/
package com.github.jaemon.dinger.multi;
+import com.github.jaemon.dinger.core.entity.enums.IgnoreMethod;
+
+import java.util.HashMap;
+import java.util.Map;
+
/**
* MultiDingerProperty
*
@@ -24,8 +29,21 @@
public class MultiDingerProperty {
/** app start at multiDinger */
static boolean multiDinger = false;
+ protected static Map ignoreMethodMap = new HashMap<>();
+
+ static {
+ for (
+ IgnoreMethod ignoreMethod : IgnoreMethod.values()
+ ) {
+ ignoreMethodMap.put(ignoreMethod.getMethodName(), ignoreMethod);
+ }
+ }
protected static boolean multiDinger() {
return multiDinger;
}
+
+ protected static void clear() {
+ ignoreMethodMap.clear();
+ };
}
\ No newline at end of file
diff --git a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java
index 6581abe..5a14787 100644
--- a/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java
+++ b/src/main/java/com/github/jaemon/dinger/multi/MultiDingerRefresh.java
@@ -28,6 +28,7 @@ public class MultiDingerRefresh extends DingerRefresh {
protected static void multiDingerRefresh() {
dingerFresh();
+ MultiDingerProperty.clear();
MultiDingerAlgorithmInjectRegister.clear();
MultiDingerConfigContainer.clear();
}
diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories
index 8302e3c..874c050 100644
--- a/src/main/resources/META-INF/spring.factories
+++ b/src/main/resources/META-INF/spring.factories
@@ -1,6 +1,7 @@
# Auto Configuration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.github.jaemon.dinger.config.BeanConfiguration,\
+com.github.jaemon.dinger.config.DingerAutoConfiguration,\
com.github.jaemon.dinger.config.DingerConfiguration,\
com.github.jaemon.dinger.config.DingerHttpClientConfig,\
com.github.jaemon.dinger.config.DingerThreadPoolConfig