-
@Bean
注解的方法被继承后注解依然有效,依然可以被扫描和注入。 -
SpringBoot的测试方式
//开启事务 @Transactional //提供spring的测试器 @RunWith(SpringRunner.class) //设置启动类 @SpringBootTest(classes = TestApplication.class) public class WxAppletInfoTest { @Test //回滚 @Rollback public void saveEventTest(){ }
-
@Value
注解注入静态变量时需要写在非静态的set
方法上
注意://需要加入 @Component 注解,否则不会扫描导致无法注入 @Component public class WxAppletInfo { /** 小程序 appId */ private static String appid; @Value("${bootx.weixin.applet.appid:}") public void setAppid(String appid) { WxAppletInfo.appid = appid; }
@Value
使用的是spel表达式, 设置默认值方式一般为{取值表达式}}:[默认值]
:
是空值时注入默认值,?:
相当于三目运算符. -
自定义配置让yml中有提示
第一种,新建一个类set/get方法触发提示
@Component @ConfigurationProperties(prefix = "bootx.security.shiro") public class ShiroConfigYml { private boolean enable; public boolean isEnable() { return enable; } public void setEnable(boolean enable) { this.enable = enable; } }
-
spring boot maven 打包插件
<build> <plugins> <!--spring boot插件--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!--主类的名称。如果未指定第一个发现编译后的类包含一个主要的方法将被使用。--> <mainClass>cn.bootx.run.Application</mainClass> <!--可执行jar文件名称后缀--> <classifier>run</classifier> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
-
spring boot maven打包时跳过测试
第一种 pom.xml中配置
<properties> <!--跳过运行测试,maven提供的选项--> <skipTests>true</skipTests> </properties>
其他
- 运行指令添加参数
- IDEA插件选择关闭测试按钮
-
SpringBoot 使用AOP
- 导入spring boot的aop starter
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency>
- 添加
@EnableAspectJAutoProxy
开启项目的AOP功能,@EnableAspectJAutoProxy public class AdminAppliation { }
- 编写一个带有
@Aspect
注解的切面类@Aspect @Component public class WebLogAspect { }
- 导入spring boot的aop starter
转载于:https://my.oschina.net/u/2555967/blog/2995572