如果只使用nutz操作dao,其他用spring+springMVC,该怎么配置注入dao?
2 回复
db.xml from db.properties
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="fileEncoding" value="UTF-8"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath*:/custom/db.properties</value><!-- 开发环境数据源 -->
<value>file:/var/config/db.properties</value><!-- 生产环境数据源 -->
</list>
</property>
</bean>
<bean id="nutDao" class="org.nutz.dao.impl.NutDao">
<property name="dataSource" ref="dataSource"/>
<property name="runner" ref="springDaoRunner"/>
</bean>
<bean id="springDaoRunner" class="org.nutz.integration.spring.SpringDaoRunner">
</bean>
<!-- druid数据库连接池配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${db.url}"/>
<property name="driverClassName" value="${db.driver}"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.pwd}"/>
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="${db.filters}"/>
<!-- 配置初始化大小、最小、最大 -->
<property name="maxActive" value="${db.pool.max}"/>
<property name="initialSize" value="${db.pool.init}"/>
<property name="minIdle" value="${db.pool.min}"/>
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="${db.pool.wait}"/>
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${db.time.betw}"/>
<property name="minEvictableIdleTimeMillis" value="${db.time.met}"/>
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="validationQuery" value="${db.query.val}"/>
<property name="testWhileIdle" value="${db.test.idle}"/>
<property name="testOnBorrow" value="${db.test.borr}"/>
<property name="testOnReturn" value="${db.test.return}"/>
<property name="connectionProperties" value="${connectionProperties}"/>
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements">
<value>true</value>
</property>
<property name="maxOpenPreparedStatements">
<value>20</value>
</property>
</bean>
<!-- 声明事务,自动管理配置数据源 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!-- 用注解来实现事务管理 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
application.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<task:executor id="myExecutor" pool-size="5"/>
<task:annotation-driven executor="myExecutor"/>
<bean class="cn.wizzer.baseframework.view.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<!-- @ResponseBody 输出纯文本 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/xml;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- @ResponseBody 输出json-->
<bean class="org.nutz.integration.spring.NutzJsonMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/json;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
<property name="prefixReturnValueHandlers">
<list>
<!-- @Json 输出json-->
<bean class="cn.wizzer.baseframework.view.annotation.SJsonReturnHandler"/>
<!-- @SFlie 输出文件-->
<bean class="cn.wizzer.baseframework.view.annotation.SFileReturnHandler"/>
</list>
</property>
<property name="prefixArgumentResolver">
<list>
<!-- bootstrap DataTables -->
<bean class="cn.wizzer.baseframework.page.datatable.DataTableResolver"/>
</list>
</property>
</bean>
<mvc:annotation-driven/>
<!-- 启用spring mvc 注解 -->
<context:annotation-config/>
<!-- 设置使用注解的类所在的jar包 -->
<context:component-scan base-package="cn.wizzer"/>
<!-- AOP切面配置,实现自定义注解 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 导入其他配置文件 -->
<import resource="classpath*:/ioc/db.xml"/>
<!-- 必须启用 -->
<import resource="classpath*:/ioc/quartz.xml"/>
<!-- 必须启用 -->
<import resource="classpath*:/ioc/redis.xml"/>
<!-- 必须启用 -->
<import resource="classpath*:/ioc/cache.xml"/>
<!-- 必须启用 -->
<import resource="classpath*:/ioc/shiro.xml"/>
<!-- 集群部署时启用 -->
<import resource="classpath*:/ioc/rabbit.xml"/>
<!-- 需要邮件服务时启用 -->
<import resource="classpath*:/ioc/mail.xml"/>
<!-- 初始化SpringBeans工具类applicationContext及其他内容-->
<bean class="cn.wizzer.app.web.commons.listener.ApplicationInitRunner"/>
<!-- 加载所有配置文件-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:custom/*.properties</value>
</list>
</property>
</bean>
<bean name="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init">
<property name="configFileResource" value="classpath:custom/beetl.properties"/>
</bean>
<bean name="nutFilePool" class="org.nutz.filepool.NutFilePool">
<constructor-arg type="java.lang.String" value="~/aebiz/tmp" />
<constructor-arg type="long" value="500" />
</bean>
<!-- Beetl视图解析器 -->
<bean name="beetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
<!-- 多视图解析器,需要设置viewNames和order -->
<property name="viewNames">
<list>
<value>pages/**</value>
</list>
</property>
<property name="suffix" value=".html"/>
<property name="contentType" value="text/html;charset=UTF-8"/>
<property name="order" value="0"/>
<!-- 多GroupTemplate,需要指定使用的bean -->
<property name="config" ref="beetlConfig"/>
</bean>
<!-- JSP视图解析器 -->
<bean name="JSPViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 注意JSP的这个视图解析器order必须在最后 -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="order" value="254"/>
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
<property name="contentType" value="text/html;charset=UTF-8"/>
</bean>
<!-- 静态资源访问配置 -->
<mvc:resources mapping="/assets/**" location="/assets/" cache-period="31556926"/>
<mvc:resources mapping="/upload/**" location="/upload/" cache-period="31556926"/>
<!-- 支持上传文件 5M -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="UTF-8" p:maxUploadSize="5242880" p:uploadTempDir="upload/temp"/>
<!-- 配置信息加载,后台获取值通过:
@Autowired
PropertiesProxy config
-->
<bean id="config" class="org.nutz.ioc.impl.PropertiesProxy">
<constructor-arg type="boolean" value="false"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="paths">
<list>
<value>custom</value>
</list>
</property>
</bean>
<!-- 国际化字符串加载 -->
<bean class="cn.wizzer.baseframework.base.Message">
<constructor-arg type="java.lang.String" value="locales"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="zh_CN"/>
</bean>
<!-- 拦截器 -->
<mvc:interceptors>
<!-- debug模式打印url执行时间 -->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/assets/**"/>
<mvc:exclude-mapping path="/upload/**"/>
<bean class="cn.wizzer.app.web.commons.interceptor.LogTimeInterceptor"/>
</mvc:interceptor>
<!-- 设置全局变量 -->
<bean class="cn.wizzer.app.web.commons.interceptor.GlobalsInterceptor"/>
<!-- 国际化字符串切换语言 -->
<bean class="cn.wizzer.app.web.commons.interceptor.LocaleInterceptor">
<property name="paramName" value="lang"/>
</bean>
<!-- Api Token -->
<mvc:interceptor>
<mvc:mapping path="/open/api/**"/>
<mvc:exclude-mapping path="/open/api/token/**"/>
<bean class="cn.wizzer.app.web.commons.interceptor.TokenInterceptor"/>
</mvc:interceptor>
<!-- 系统管理后台shiro拦截器,商户/会员/可参考来实现 -->
<mvc:interceptor>
<mvc:mapping path="/platform/**"/>
<mvc:exclude-mapping path="/platform/login/**"/>
<mvc:exclude-mapping path="//platform/dec/templates/manager/run"/>
<mvc:exclude-mapping path="//platform/dec/templates/files/getFile"/>
<mvc:exclude-mapping path="//platform/dec/templates/files/getSkin"/>
<bean class="cn.wizzer.app.web.commons.interceptor.PlatformShiroInterceptor"/>
</mvc:interceptor>
<!-- 商家中心后台shiro拦截器 -->
<mvc:interceptor>
<mvc:mapping path="/store/**"/>
<mvc:exclude-mapping path="/store/login/**"/>
<mvc:exclude-mapping path="/store/join/**"/> <!-- 加入商家不拦截 -->
<bean class="cn.wizzer.app.web.commons.interceptor.StoreShiroInterceptor"/>
</mvc:interceptor>
<!-- 会员中心shiro拦截器 -->
<mvc:interceptor>
<mvc:mapping path="/member/**"/>
<mvc:exclude-mapping path="/member/login/**"/>
<mvc:exclude-mapping path="/member/register/**"/> <!-- 会员注册功能不拦截 -->
<mvc:exclude-mapping path="/member/fogetPassword/**"/> <!-- 会员忘记密码功能不拦截 -->
<bean class="cn.wizzer.app.web.commons.interceptor.MemberShiroInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
</beans>
@Service
public class SysApiServiceImpl extends BaseServiceImpl<Sys_api> implements SysApiService {
@Resource(name = "nutDao", type = Dao.class)
public void init(Dao dao) {
super.setDao(dao);
}
添加回复
请先登陆