3.7.6版本填值规则IFillRuleHandler类中@Autowired注入service失败
jeecg3.7.6版本。我就想在实现IFillRuleHandler接口的填值规则类中,调用代码生成器生成的service类。@Autowired注入service失败,为什么一直报空指针异常。那样我怎么在填值规则类中查询数据库啊。找了下问题贴只找到这个http://www.jeecg.org/forum.php?mod=viewthread&tid=1832&extra= 解决不了,我的填值规则类是放在com.jeecg.operation.enhance包下的package com.jeecg.operation.enhance;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.jeecgframework.web.cgform.enhance.IFillRuleHandler;
import org.jeecgframework.web.system.service.impl.SystemServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.jeecg.counter.entity.LmCounterEntity;
import com.jeecg.operation.service.LmMemberServiceI;
@Component("memberCode")
public class MemberCodeAutoFill implements IFillRuleHandler {
@Autowired
private LmMemberServiceI lmMemberService;
@Override
public String execute(String paramJson) {
new SystemServiceImpl();
String pattern="yyyyMMdd";
SimpleDateFormat dateFormat=new SimpleDateFormat(pattern);
String membercode = dateFormat.format(new Date());
String hql0 = "from LmCounterEntity where 1 = 1 AND countercode = ? ";
List<LmCounterEntity> lmCounterEntityList = lmMemberService.findHql(hql0,"membercode");
for (LmCounterEntity lmCounterEntity : lmCounterEntityList) {
int count = lmCounterEntity.getCount();
String newString = String.format("%0"+4+"d", count);
membercode = membercode+newString;
count = (count+1)%10000;
lmCounterEntity.setCount(count);
}
return membercode;
}
}
看扫描路径的配置 本帖最后由 sinsign 于 2018-7-22 00:29 编辑
admin 发表于 2018-7-21 23:50 static/image/common/back.gif
看扫描路径的配置该配置的都配置了 没看出问题在哪里
spring-mvc-hibernate.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
default-autowire="byName" default-lazy-init="false">
<!-- 自动扫描dao和service包(自动注入) -->
<context:component-scan base-package="org.jeecgframework.easypoi.*" />
<context:component-scan base-package="org.jeecgframework.core.common.dao.*" />
<context:component-scan base-package="org.jeecgframework.core.common.service.*" />
<context:component-scan base-package="org.jeecgframework.jwt.service.*"/>
<context:component-scan base-package="com.jeecg.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 加载service,此时要排除要controller,因为controller已经spring-mvc中加载过了 -->
<context:component-scan base-package="org.jeecgframework.web.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 引入属性文件 -->
<context:property-placeholder location="classpath:dbconfig.properties" ignore-unresolvable="true"/>
<!-- 配置数据源1 -->
<bean name="dataSource_jeecg" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url.jeecg}" />
<property name="username" value="${jdbc.username.jeecg}" />
<property name="password" value="${jdbc.password.jeecg}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="0" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="50" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="5" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="60000" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="validationQuery" value="${validationQuery.sql}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<!-- 开启Druid的监控统计功能 -->
<property name="filters" value="stat" />
<!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="3600" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
<!-- Oracle连接是获取字段注释 -->
<property name="connectProperties">
<props>
<prop key="remarksReporting">true</prop>
</props>
</property>
</bean>
<!-- 数据源集合 -->
<bean id="dataSource"
class="org.jeecgframework.core.extend.datasource.DynamicDataSource">
<property name="targetDataSources">
<map key-type="org.jeecgframework.core.extend.datasource.DataSourceType">
<entry key="dataSource_jeecg" value-ref="dataSource_jeecg" />
<!-- <entry key="mapdataSource" value-ref="mapdataSource" /> -->
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSource_jeecg" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="entityInterceptor" ref="hiberAspect" />
<property name="hibernateProperties">
<props>
<!--<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> -->
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
</props>
</property>
<!-- 注解方式配置 -->
<property name="packagesToScan">
<list>
<value>org.jeecgframework.web.system.pojo.*</value>
<value>org.jeecgframework.web.test.entity.*</value>
<value>org.jeecgframework.web.autoform.*</value>
<value>org.jeecgframework.web.cgform.entity.*</value>
<value>org.jeecgframework.web.cgreport.entity.*</value>
<value>org.jeecgframework.web.cgdynamgraph.entity.*</value>
<value>org.jeecgframework.web.graphreport.entity.*</value>
<value>org.jeecgframework.web.system.sms.*</value>
<value>org.jeecgframework.web.black.*</value>
<value>org.jeecgframework.web.superquery.*</value>
<value>com.jeecg.*</value>
</list>
</property>
</bean>
<!-- JDBC配置 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!-- JDBC配置 -->
<bean id="namedParameterJdbcTemplate"
class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
<!-- 配置事物管理器,在*ServiceImpl里写@Transactional就可以启用事物管理 -->
<bean name="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- JSR303 Validator定义 -->
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
</beans> admin 发表于 2018-7-21 23:50 static/image/common/back.gif
看扫描路径的配置
该配置的都配置了spring-mvc.xml 还是报错<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<!-- 加载controller的时候,不加载service,因为此时事物并未生效,若此时加载了service,那么事物无法对service进行拦截 -->
<context:component-scan base-package="org.jeecgframework.web.*,com.jeecg.*,org.jeecgframework.jwt.*">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>
<!-- ApplicationContext-->
<bean class="org.jeecgframework.core.util.ApplicationContextUtil"></bean>
<!-- Swagger支持(暂时注释掉提高平台性能,需要此功能,可以放开注释)
<context:component-scan base-package="springfox"/>
<bean class="org.jeecgframework.core.swagger.SwaggerConfig" />
<mvc:resources mapping="/swagger/**" location="/swagger/" cache-period="31556926" />-->
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="customObjectMapper"></property>
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/json;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- ResponseBody返回字符串带双引号解决 -->
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" index="0"/>
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
<bean id="customObjectMapper" class="org.jeecgframework.core.common.controller.CustomObjectMapper"></bean>
<!-- 注册handler method和request的mapping关系。-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射, 配置一个基于注解的定制的WebBindingInitializer,解决日期转换问题,方法级别的处理器映射 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="cacheSeconds" value="0" />
<property name="messageConverters">
<list>
<ref bean="stringHttpMessageConverter" /> <!--先进行string转换-->
<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
</list>
</property>
<property name="webBindingInitializer">
<bean class="org.jeecgframework.core.interceptors.MyWebBinding" />
</property>
</bean>
<!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->
<bean id="defaultViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="3">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="contentType" value="text/html" />
<property name="prefix" value="/webpage/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="UTF-8">
<property name="maxUploadSize">
<value>104857600</value>
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean>
<!-- Bean解析器,级别高于默认解析器,寻找bean对象进行二次处理 -->
<bean id="beanNameViewResolver"
class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="0">
</bean>
<!-- Excel 处理 根据用户输入进行对象处理 -->
<bean id="jeecgExcelView" class="org.jeecgframework.poi.excel.view.JeecgSingleExcelView" />
<bean id="jeecgTemplateExcelView" class="org.jeecgframework.poi.excel.view.JeecgTemplateExcelView" />
<bean id="jeecgTemplateWordView" class="org.jeecgframework.poi.excel.view.JeecgTemplateWordView" />
<bean id="jeecgMapExcelView" class="org.jeecgframework.poi.excel.view.JeecgMapExcelView" />
<!-- 方言 -->
<bean id="dialect"
class="org.jeecgframework.core.common.hibernate.dialect.DialectFactoryBean">
<property name="dbType" value="${jdbc.dbType}" />
</bean>
<!-- 异常处理类 -->
<bean id="exceptionHandler"
class="org.jeecgframework.core.common.exception.GlobalExceptionResolver" />
<!--单点登录 kisso 注入初始化,也支持使用 web.xml 初始化 (暂时注释掉提高平台性能,需要此功能,可以放开注释) -->
<!--参数runMode说明: dev_mode/开发模式 ,test_mode/测试模式 ,online_mode/生产模式
<bean id="kissoInit" class="com.baomidou.kisso.web.WebKissoConfigurer" init-method="initKisso">
<property name="ssoPropPath" value="sso.properties" />
<property name="runMode" value="test_mode" />
</bean> -->
<!-- 拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="org.jeecgframework.core.interceptors.EncodingInterceptor" />
</mvc:interceptor>
<!-- [接口方案一] API 接口验签拦截器 ,签名统一校验(暂时注释掉提高平台性能,需要此功能,可以放开注释)
<mvc:interceptor>
<mvc:mapping path="/api/**" />
<bean class="org.jeecgframework.core.interceptors.SignInterceptor" />
</mvc:interceptor>-->
<!-- [接口方案二] JWT Token校验方式拦截器,针对Restful请求接口 -->
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/**/**.do" />
<mvc:exclude-mapping path="/**/**.do?**" />
<bean class="org.jeecgframework.jwt.aop.RestAuthTokenInterceptor">
<property name="excludeUrls">
<list>
<value>/rest/v2/api-docs</value>
</list>
</property>
<property name="excludeContainUrls">
<list>
<value>/rest/tokens</value>
</list>
</property>
</bean>
</mvc:interceptor>
<!-- 登录权限拦截器 -->
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="org.jeecgframework.core.interceptors.AuthInterceptor">
<property name="excludeUrls">
<list>
<value>loginController.do?goPwdInit</value>
<value>loginController.do?pwdInit</value>
<value>loginController.do?login</value>
<value>loginController.do?logout</value>
<value>loginController.do?changeDefaultOrg</value>
<value>loginController.do?login2</value>
<value>loginController.do?login3</value>
<value>loginController.do?checkuser</value>
<value>loginController.do?checkuser=</value>
<value>systemController.do?saveFiles</value>
<!-- 邮件密码重置 -->
<value>loginController.do?goResetPwd</value>
<value>loginController.do?resetPwd</value>
<value>loginController.do?goResetPwdMail</value>
<value>loginController.do?sendResetPwdMail</value>
<value>userController.do?userOrgSelect</value>
<!--移动图表-->
<value>cgDynamGraphController.do?design</value>
<value>cgDynamGraphController.do?datagrid</value>
<!-- 菜单样式图标预览 -->
<value>webpage/common/functionIconStyleList.jsp</value>
<value>chat/imController/showOrDownByurl.do</value>
<!-- 接收远程定时任务开关指令 -->
<value>timeTaskController.do?remoteTask</value>
<!-- swagger支持-->
<value>rest/v2/api-docs</value>
</list>
</property>
<!-- 模糊匹配 -->
<property name="excludeContainUrls">
<list>
<!--单点登录-->
<value>toLogin.do</value>
<!--restful请求统一不做拦截,采用jwt接口机制验证-->
<value>rest/</value>
</list>
</property>
</bean>
</mvc:interceptor>
<!-- SQL注入拦截器 (暂时注释掉提高平台性能,需要此功能,可以放开注释)
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="org.jeecgframework.core.interceptors.SqlInjectInterceptor">
<property name="onlineOptUrls">
<list>
Online表单SQL增强
<value>cgformButtonSqlController.do?save</value>
Online数据报表
<value>cgreportConfigHeadController.do?doAdd</value>
<value>cgreportConfigHeadController.do?doUpdate</value>
<value>cgReportController.do?getFields</value>
Online图形报表
<value>jformGraphreportHeadController.do?doAdd</value>
<value>jformGraphreportHeadController.do?doUpdate</value>
<value>graphReportController.do?getFields</value>
Online移动报表
<value>cgDynamGraphConfigHeadController.do?doAdd</value>
<value>cgDynamGraphConfigHeadController.do?doUpdate</value>
<value>cgDynamGraphController.do?getFields</value>
</list>
</property>
</bean>
</mvc:interceptor> -->
</mvc:interceptors>
<!--集成cxf webservice接口(暂时注释掉提高平台性能,需要此功能,可以放开注释)
<import resource="classpath:cxf-servlet.xml" />-->
<!-- Online表单配置引入 -->
<import resource="classpath*:org/jeecgframework/web/cgform/common/spring-mvc-cgform.xml" />
<!-- 配置 redis -->
<import resource="classpath:redis.xml" />
<!-- Jeecg 插件开发 -->
<bean class="org.jeecgframework.p3.core.utils.common.ApplicationContextUtil"></bean>
<import resource="classpath:config/spring-config-p3.xml" />
</beans> 看常见问题贴,代码生成器生成后,扫描路径配置
页:
[1]