Not registered via @EnableConfigurationProperties,
marked as Spring component, or scanned via @ConfigurationPropertiesScan.
当使用@ConfigurationProperties时IDEA顶部出现这样的提示:
错误原因:
ConfigurationProperties使用spring-boot-configuration-processor jar 轻松地从带有注释的项目中生成自己的配置元数据文件 。
该jar包含一个Java注释处理器,在项目被编译时会被调用。要使用处理器,请包含对的依赖 spring-boot-configuration-processor。
1. 在配置文件pom.xml中添加依赖:
2. 回到自定义的bean Person中,添加注解@Component,声明将这个组件添加至容器中,这样才可以被使用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
若target中classes目录下的mapper目录下的xml目录不存在
配置如下方法XMl才能被扫描到
方法1
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<!--指定src/main/resources资源要过滤-->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
方法2
!--在build中配置resources,来防止我们资源导出失败的问题-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
进行spring与mybatis进行整合的时候遇到了一个错误,报错如下
Error attempting to get column 'title' from result set.
其实代码没错,是因为实体类中少了无参构造方法,加上即可。
@AllArgsConstructor
@NoArgsConstructor
由于springFramework 中配置了springSecurity的依赖而报错 因为admin-blog 引入了springFramework
Field authenticationManager in com.sangeng.service.impl.BlogLoginServiceImpl
required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found.
The injection point has the following annotations:
@org.springframework.beans.factory.annotation.Autowired(required=true)
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
@Bean // 注入容器
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Autowired
private JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
@Autowired
AuthenticationEntryPoint authenticationEntryPoint;
@Autowired
AccessDeniedHandler accessDeniedHandler;
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
//关闭csrf (前后端分离)
.csrf().disable()
//不通过Session获取SecurityContext
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
// 对于登录接口 允许匿名访问
.antMatchers("/user/login").anonymous()
//.antMatchers("/logout").authenticated()
//.antMatchers("/comment").authenticated()
//.antMatchers("/upload").authenticated()
//.antMatchers("/link/getAllLink").authenticated() 不需要认证后才能查询
// 除上面外的所有请求全部不需要认证即可访问
.anyRequest().authenticated();
//配置异常处理器
http.exceptionHandling()
.authenticationEntryPoint(authenticationEntryPoint)
.accessDeniedHandler(accessDeniedHandler);
// 关于springSecurity的默认注销功能
http.logout().disable();
//把jwtAuthenticationTokenFilter添加到SpringSecurity的过滤器链中
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
//允许跨域
http.cors();
}
}
Invalid bound statement (not found): 在这里使用sql语句解决
问题描述:查看了target中clasees目录里的mapper目录下的xml文件发现已经映射成功!
但仍然报错:Invalid bound statement (not found): 可采用sql语句语句解决
package com.sangeng.mapper;
import com.sangeng.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface MenuMapper extends BaseMapper<Menu> {
// bug Invalid bound statement (not found): 在这里使用sql语句解决
@Select( " SELECT " +
" DISTINCT m.id, m.parent_id, m.menu_name, m.path, m.component, m.visible, m.status, " +
" IFNULL(m.perms,'') AS perms, m.is_frame, m.menu_type, m.icon, m.order_num, m.create_time " +
"FROM " +
"`sys_menu` m " +
"WHERE " +
"m.`menu_type` IN ('C','M') AND " +
"m.`status` = 0 AND " +
"m.`del_flag` = 0 " +
"ORDER BY " +
"m.parent_id,m.order_num")
List<Menu> selectAllRouterMenu();
}
问题描述:自定义DTO(数据传输对象,Data Transfer Object),若字段名称与entity中的字段一致
sql语句正确方式如下
@Insert(" insert into sg_tag (name,remark) values (#{name},#{remark})")
boolean addTag(TagListDto tagListDto);
sql语句书写错误方式如下:
@Insert(" insert into sg_tag (name,remark) values
(#{tagListDto.getName()},#{tagListDto.getRemark()})")