idea写springboot框架所遇见问题

1. spring boot 中的service形成循环

报错:

Error creating bean with name 'xxxServiceImpl': Bean with name 'xxxServiceImpl' has been injected into other beans [XXXService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. 

解决方法:

//将下列代码:
	@Autowired
    private StuGradeService stuGraService;
 //改为:
 	@Autowired
    @Lazy
    private StuGradeService stuGraService;

2. 不能加载本地资源

报错:

The local resource could not be loaded

解决方法:

//在里面添加一个WebConfig类
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 配置string解析器放在json解析器前边
     *
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        HttpMessageConverter<?> httpMessageConverter = converters.get(0);
        converters.remove(0);
        converters.add(2, httpMessageConverter);
    }

    /**
     * 静态资源映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //swagger
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

        //添加一下两行代码,可加载对应文件里的本地资源
        registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets/");
        registry.addResourceHandler("/tmp/**").addResourceLocations("file:D:\\tmp\\");

        //流程设计器
        registry.addResourceHandler("/activiti-editor/**").addResourceLocations("classpath:/activiti-editor/");

    }

    /**
     * 默认错误页面,返回json
     */
    @Bean("error")
    public GunsErrorView error() {
        return new GunsErrorView();
    }

    /**
     * druidServlet注册
     */
    @Bean
    public ServletRegistrationBean druidServletRegistration() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new StatViewServlet());
        registration.addUrlMappings("/druid/*");
        return registration;
    }

    /**
     * druid监控 配置URI拦截策略
     */
    @Bean
    public FilterRegistrationBean druidStatFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
        //添加过滤规则.
        filterRegistrationBean.addUrlPatterns("/*");
        //添加不需要忽略的格式信息.
        filterRegistrationBean.addInitParameter(
                "exclusions", "/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid,/druid/*");
        //用于session监控页面的用户名显示 需要登录后主动将username注入到session里
        filterRegistrationBean.addInitParameter("principalSessionName", "username");
        return filterRegistrationBean;
    }

    /**
     * druid数据库连接池监控
     */
    @Bean
    public DruidStatInterceptor druidStatInterceptor() {
        return new DruidStatInterceptor();
    }

    @Bean
    public JdkRegexpMethodPointcut druidStatPointcut() {
        JdkRegexpMethodPointcut druidStatPointcut = new JdkRegexpMethodPointcut();
        String patterns = "cn.stylefeng.guns.modular.*.service.*";
        //可以set多个
        druidStatPointcut.setPatterns(patterns);
        return druidStatPointcut;
    }

    /**
     * druid数据库连接池监控
     */
    @Bean
    public BeanTypeAutoProxyCreator beanTypeAutoProxyCreator() {
        BeanTypeAutoProxyCreator beanTypeAutoProxyCreator = new BeanTypeAutoProxyCreator();
        beanTypeAutoProxyCreator.setTargetBeanType(DruidDataSource.class);
        beanTypeAutoProxyCreator.setInterceptorNames("druidStatInterceptor");
        return beanTypeAutoProxyCreator;
    }

    /**
     * druid 为druidStatPointcut添加拦截
     *
     * @return
     */
    @Bean
    public Advisor druidStatAdvisor() {
        return new DefaultPointcutAdvisor(druidStatPointcut(), druidStatInterceptor());
    }

    /**
     * xssFilter注册
     */
    @Bean
    public FilterRegistrationBean xssFilterRegistration() {
        XssFilter xssFilter = new XssFilter();
        xssFilter.setUrlExclusion(Arrays.asList("/notice/add", "/notice/update", "/excelExportDeploy/editItem", "/excelExportDeploy/addItem"));
        FilterRegistrationBean registration = new FilterRegistrationBean(xssFilter);
        registration.addUrlPatterns("/*");
        return registration;
    }

    /**
     * RequestContextListener注册
     */
    @Bean
    public ServletListenerRegistrationBean<RequestContextListener> requestContextListenerRegistration() {
        return new ServletListenerRegistrationBean<>(new RequestContextListener());
    }

    /**
     * ConfigListener注册
     */
    @Bean
    public ServletListenerRegistrationBean<ConfigListener> configListenerRegistration() {
        return new ServletListenerRegistrationBean<>(new ConfigListener());
    }

    /**
     * 验证码生成相关
     */
    @Bean
    public DefaultKaptcha kaptcha() {
        Properties properties = new Properties();
        properties.put("kaptcha.border", "no");
        properties.put("kaptcha.border.color", "105,179,90");
        properties.put("kaptcha.textproducer.font.color", "blue");
        properties.put("kaptcha.image.width", "125");
        properties.put("kaptcha.image.height", "45");
        properties.put("kaptcha.textproducer.font.size", "45");
        properties.put("kaptcha.session.key", "code");
        properties.put("kaptcha.textproducer.char.length", "4");
        properties.put("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}

3.自动启动网页

网址:https://blog.csdn.net/weixin_43171019/article/details/88074536

先配置号默认浏览器

再新写一个类,如下:

@Component
public class MyCommandRunner implements CommandLineRunner {
    @Override
    public void run(String... args) {
         System.out.println("开始自动加载指定的页面");
        try {
            Runtime.getRuntime().exec("cmd   /c   start   http://localhost:8080/");//可以指定自己的路径
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

4.错误提示Unsatisfied dependency expressed through field 'baseMapper’解决方法

解决办法是在继承了baseMapper类的接口上添加@Mapper注解,最后就跑通了

5.maven手动导入本地包后提示xxx包不存在

imgimg

如果有提示:[mvn 不是内部或外部命令,那么就是你们的maven没有配置环境变量]

注意:但是执行mvn clean install命令的时候会报错:找不到opensdk3.0.9.jar资源包(也就是刚手动添加的jar包)

使用idea的Terminal

mvn install:install-file  -DgroupId=com.opensdk  -DartifactId=opensdk  -Dversion=3.0.9  -Dpackaging=jar  -Dfile=E:\xm\erp\HegERP\ruoyi-admin\src\main\resources\lib\opensdk3.0.9.jar

-DgroupId对应为pom文件中的groupId

-DartifactId对应为pom文件中的artifactId

-Dversion对应为pom文件中的version

-Dpackaging导入包的类型是jar包的话就是jar

-Dfile你下载下来的jar包放的路径

注意:执行命令的时候,maven仓库不能存在com.opensdk.opensdk的文件夹和数据,如果存在就删掉

最后在pom文件中写入依赖

 <dependency>
            <groupId>com.opensdk</groupId>
            <artifactId>opensdk</artifactId>
            <version>3.0.9</version>
</dependency>

6.chdir is not implemented in jnr-posix

的文件夹和数据,如果存在就删掉


最后在pom文件中写入依赖

com.opensdk opensdk 3.0.9 ```

6.chdir is not implemented in jnr-posix

pom依赖包错误(类似结尾是root cause之类的错误也是pom的依赖出现问题)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值