Solon hot reload beta
Support adding and modifying beans in Solon container
Quickly call java method Support calling Solon beans
Controller
Adding or modifying Controller layer classes can be hot reloaded and Mapping annotations (such as @Mapping, @Get, @Post, etc.) information will be reparsed.
java
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
@Controller
public class DemoController {
@Inject
private DemoService demoService;
@Get
@Mapping("/demo1")
public String demo1() {
return demoService.hello3211("solon1");
}
@Get
@Mapping("/demo2")
public String demo2() {
return "demo2";
@Post
@Mapping("/demo3")
public String demo3() {
return "demo3";
}
}- The previous
/demo2is no longer accessible, but the newly added/demo3can be accessed. - The newly added
/demo1can be accessed, and the usedDemoServicewill also be injected intoDemoController.
Component
Simple AOP implementation, using the @Around annotation to print logs before and after method execution.
java
import org.noear.solon.annotation.Around;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Around(TestAopInterceptor.class)
public @interface TestAop {
}Concrete implementation class
java
import org.noear.solon.core.aspect.Interceptor;
import org.noear.solon.core.aspect.Invocation;
public class TestAopInterceptor implements Interceptor {
@Override
public Object doIntercept(Invocation inv) throws Throwable {
TestAop anno = inv.getMethodAnnotation(TestAop.class);
if (anno == null) {
anno = inv.getTargetAnnotation(TestAop.class);
}
if (anno == null) {
return inv.invoke();
}
System.out.println("before");
Object invoke = inv.invoke();
System.out.println("after");
return invoke;
}
}At this time we overload the DemoService class as follows
java
import io.github.future0923.debug.tools.test.solon.aop.TestAop;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
@Component
public class DemoService {
@Inject
private UserService userService;
@TestAop
public String hello1(String name) {
return userService.ab();
}
public String hello2(String name) {
return userService.ab();
}
public String hello3(String name) {
return userService.ab();
}
}- After overloading, when
hello1()is called, the@TestAopannotation will take effect to printbeforeandafterlogs, and theuserService.ab()method will be called. - The newly added
hello2()method can be called. - The deleted
hello3()method cannot be found.
Configuration
Added @Bean in @Configuration to create TestConfigBean
java
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
@Configuration
public class TestConfig {
public static class TestConfigBean {
public String getName() {
return "test";
}
}
@Bean
public TestConfigBean testConfigBean() {
return new TestConfigBean();
}
}Inject into DemoService and use
java
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
@Component
public class DemoService {
@Inject
private TestConfig.TestConfigBean testConfigBean;
public String hello(String name) {
return null;
return testConfigBean.getName();
}
}- The newly added
TestConfigBeancan be obtained in the container, andDemoServicecan usetestConfigBean.