bean

Intellij Idea @Autowired取消提示

谁都会走 提交于 2020-02-28 06:52:14
在使用mybatis的代理进行开发时 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.winner.mapper"/> </bean> Mapper接口通过@Autowired注入,在编辑情况下,无法找不到对应的bean,于是提示找不到对应bean的错误。 但实际上项目是正常运行的。 可在File -- Settings -- Inspections。在Spring Core -- Autowring for Bean Class 中, 将Severity的级别由之前的error改成warning。 Mapper接口通过@Autowired注入,在编辑情况下,无法找不到对应的bean,于是提示找不到对应bean的错误。 但实际上项目是正常运行的。 可在File -- Settings -- Inspections。在Spring Core -- Autowring for Bean Class 中, 将Severity的级别由之前的error改成warning。 来源: https://www.cnblogs.com/winner-0715/p/5534694.html

Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用

北城以北 提交于 2020-02-28 04:54:36
扩展阅读: 注释驱动的 Spring cache 缓存介绍 spring boot + spring cache 实现两级缓存(redis + caffeine) 从3.1开始,Spring引入了对Cache的支持。其使用方法和原理都类似于Spring对事务管理的支持。Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该方法参数和返回结果作为一个键值对存放在缓存中,等到下次利用同样的参数来调用该方法时将不再执行该方法,而是直接从缓存中获取结果进行返回。所以在使用Spring Cache的时候我们要保证我们缓存的方法对于相同的方法参数要有相同的返回结果。 使用Spring Cache需要我们做两方面的事: n 声明某些方法使用缓存 n 配置Spring对Cache的支持 和Spring对事务管理的支持一样,Spring对Cache的支持也有基于注解和基于XML配置两种方式。下面我们先来看看基于注解的方式。 1 基于注解的支持 Spring为我们提供了几个注解来支持Spring Cache。其核心主要是@Cacheable和@CacheEvict。使用@Cacheable标记的方法在执行后Spring Cache将缓存其返回结果,而使用@CacheEvict标记的方法会在方法执行前或者执行后移除Spring Cache中的某些元素

springcloud Feign使用时,某服务A调用服务B的类时,找不到

徘徊边缘 提交于 2020-02-28 04:12:43
*************************** APPLICATION FAILED TO START *************************** Description: Field productClient in com.imooc.order.service.impl.OrderServiceImpl required a bean of type 'com.imooc.product.client.ProductClient' that could not be found. Action: Consider defining a bean of type 'com.imooc.product.client.ProductClient' in your configuration. 这是因为没有扫描到这些类, @EnableFeignClients(basePackages = "com.imooc.product.client") 应该有这功能的,但没起到效果,所以又加上了如下 @ComponentScan(basePackages = "com.imooc.product.client") 来源: CSDN 作者: 千百元 链接: https://blog.csdn.net/liuming690452074/article/details

spring拾遗(一)——IOC的应用

陌路散爱 提交于 2020-02-28 03:45:05
前言 spring这个玩意,其实要单纯谈使用的话,其实内容也不少,工作中有些东西用的挺多,但是很不系统。去年也尝试过看spring的源码,但是通常陷入到"我是谁,我在哪儿的,我干嘛要看这玩意"的思考(因为太晕了),想想这玩意还是得学啊,不能因为不懂,不能因为它让我怀疑人生就放弃,还是得从头撸。后来思考发现自己太过依赖百度,忽略了官网这玩意,这次就从官网出发。总结一些更多的操作,让spring的学习更加系统。这篇博客并不是一个官网的翻译,整理的内容会非常零散,毕竟只是补充我们平常使用spring框架忽略的东西。 什么是IOC,IOC和DI有啥区别 这又是一个灵魂拷问,在面试中遇到过很多次,不同的人回答方式不同。个人觉得这个东西一句话就能解决,DI其实就是IOC的一种实现,IOC只是一种设计理念。除了DI的方式来实现IOC,DL的方式也是IOC的一种实现。(之前有一种说法,DI是IOC的另一种表达方式,感觉不太全面) 控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。其中最常见的方式叫做依赖注入(Dependency Injection,简称 DI ),还有一种方式叫“依赖查找”(Dependency Lookup ) 为什么要有IOC 自己new它不香吗?不好意思,自己new,真的香不起来

WebSocket connection to '*' failed: Error during WebSocket handshake: Unexpected response code: 404

狂风中的少年 提交于 2020-02-27 16:35:38
Spring boot 2.0配置WebSocket 出现WebSocket connection to 'ws://localhost:8080/websocket/3c9d8e1e0cf24bfdbc65b8f24367def3' failed: Error during WebSocket handshake: Unexpected response code: 404 1.首先排查路径是否正确; 2.如果路径没有问题, 检查是否配置ServerEndpointExporter; @Component public class WebSocketConfig { /** * ServerEndpointExporter 作用 * * 这个Bean会自动注册使用@ServerEndpoint注解声明的websocket endpoint * * @return */ @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); } } WebSocket 注册的bean默认是自己管理,没有托管给spring。需要将WebSocket的bean托管给spring容器。 来源: CSDN 作者: lizhaoyang1975 链接: https:

吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Spring_PropertyPathFactoryBean

我的未来我决定 提交于 2020-02-27 15:21:28
<?xml version="1.0" encoding="GBK"?> <project name="spring" basedir="." default=""> <property name="src" value="src"/> <property name="dest" value="classes"/> <path id="classpath"> <fileset dir="../../lib"> <include name="**/*.jar"/> </fileset> <pathelement path="${dest}"/> </path> <target name="compile" description="Compile all source code"> <delete dir="${dest}"/> <mkdir dir="${dest}"/> <copy todir="${dest}"> <fileset dir="${src}"> <exclude name="**/*.java"/> </fileset> </copy> <javac destdir="${dest}" debug="true" includeantruntime="yes" deprecation="false" optimize="false" failonerror=

Spring Boot入门(六) 之 @PropertyResource

对着背影说爱祢 提交于 2020-02-27 14:58:00
用来加载指定的配置文件 我们前边在给bean文件注入数据的时候,使用了 @ConfigurationProperties 注解,不过该注解,只可以把应用主配置文件的内容读取进来,要想给Bean赋值,只能读取主配置文件,就是 application.properties 或者 application.yml 文件,若我们想自己写一个配置文件来给bean赋值,我们就可以使用该注解 @PropertyResource 我们在resource里边新建一个 person.properties 文件,并把之前主配置文件里的内容剪贴进来,并在bean上边加上注解 @PropertySource ( value = { "classpath:person.properties" } ) 这里的value是一个列表可以添加多个配置文件,classpath指的是类路径,表示类路径下的person.properties文件 来源: CSDN 作者: 锋霜利雪 链接: https://blog.csdn.net/weixin_44415928/article/details/104534823

吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Spring_MethodInvokingFactoryBean

冷暖自知 提交于 2020-02-27 14:44:52
<?xml version="1.0" encoding="GBK"?> <project name="spring" basedir="." default=""> <property name="src" value="src"/> <property name="dest" value="classes"/> <path id="classpath"> <fileset dir="../../lib"> <include name="**/*.jar"/> </fileset> <pathelement path="${dest}"/> </path> <target name="compile" description="Compile all source code"> <delete dir="${dest}"/> <mkdir dir="${dest}"/> <copy todir="${dest}"> <fileset dir="${src}"> <exclude name="**/*.java"/> </fileset> </copy> <javac destdir="${dest}" debug="true" includeantruntime="yes" deprecation="false" optimize="false" failonerror=

spring datasourses 配置

风格不统一 提交于 2020-02-27 09:06:09
<beans>   <bean name="datasource" class="org.apache.commons.dbcp.BasicDataSource">     <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>     <property name="url" value="jdbc:oracle:thin:@localhost:3307:test"/>     <property name="username" value="root"/>     <property name="password" value="root"/>   </bean>   <bean name="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">      <property name="dataSource" ref="datasource"/>   </bean>   <tx:advice id="txAdvice" transaction-manager="txManager">     <tx:attributes>       <tx:method name=

Maven+SSM框架(Spring+SpringMVC+MyBatis)(二)

放肆的年华 提交于 2020-02-27 08:59:29
1.基本概念 2.开发环境搭建 3.Maven Web项目创建 4.SSM整合 此次整合我分两个配置文件:   1)分别是spring-mybatis.xml,包含spring和mybatis的配置文件,   2)还有个是spring-mvc的配置文件,   3)此外有2个资源文件:jdbc.propertis和log4j.properties 以下是框架版本及来源 :   Spring 4.0.2 RELEASE(PS:无需手动下载,Maven会自动下)   Spring MVC 4.0.2 RELEASE(PS:无需手动下载,Maven会自动下)   MyBatis 3.2.6 *打开 xml 文件的代码提示功能 打 开 Eclipse 依次选择 Window > Preferences > Xml > Xml Files > Editor > Content Assist > Auto activation > Prompt when these characters are inserted,设置框中默认是 <=: ,改成<=:qwertyuioplkjhgfdsazxcvbnm就ok了。 下面是项目完整结构,先有个印象 : 4.1 Maven引入需要的jar包 为了方便后面说的时候不需要引入JAR包,我这里直接给出所有需要的JAR包,这都是基本的JAR包