持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第31天,点击查看活动详情
applicationContext-service.xml
<!-- 设置业务逻辑层的包扫描器,目的是在指定的路径下,\
使用@Service注解的类,Spring负责创建对象,并添加依赖\
-->\
<context:component-scan base-package="com.bjpowernode.service"></context:component-scan>\
<!-- 设置事务管理器-->\
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">\
<property name="dataSource" ref="dataSource"></property>\
</bean>\
<!-- 添加事务的切面-->\
<tx:advice id="myadvice" transaction-manager="transactionManager">\
<tx:attributes>\
<tx:method name="*select*" read-only="true"/>\
<tx:method name="*find*" read-only="true"/>\
<tx:method name="*get*" read-only="true"/>\
<tx:method name="*search*" read-only="true"/>\
<tx:method name="*insert*" propagation="REQUIRED"/>\
<tx:method name="*save*" propagation="REQUIRED"/>\
<tx:method name="*add*" propagation="REQUIRED"/>\
<tx:method name="*delete*" propagation="REQUIRED"/>\
<tx:method name="*remove*" propagation="REQUIRED"/>\
<tx:method name="*clear*" propagation="REQUIRED"/>\
<tx:method name="*update*" propagation="REQUIRED"/>\
<tx:method name="*modify*" propagation="REQUIRED"/>\
<tx:method name="*change*" propagation="REQUIRED"/>\
<tx:method name="*set*" propagation="REQUIRED"/>\
<tx:method name="*" propagation="SUPPORTS"/>\
</tx:attributes>\
</tx:advice>\
<!-- 完成切面和切入点的织入-->\
<aop:config>\
<aop:pointcut id="mypointcut" expression="execution(* com.bjpowernode.service.*.*(..))"/>\
<aop:advisor advice-ref="myadvice" pointcut-ref="mypointcut"></aop:advisor>\
</aop:config>
Springmvc.xml
<!-- 设置包扫描器-->\
<context:component-scan base-package="com.bjpowernode.controller"></context:component-scan>\
<!-- 设置视图解析器 /admin/ main .jsp -->\
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">\
<property name="prefix" value="/admin/"></property>\
<property name="suffix" value=".jsp"></property>\
</bean>\
<!-- 设置文件上传核心组件-->\
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">\
</bean>\
<!-- 设置注解驱动-->\
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 解决跨域问题-->
<mvc:cors>\
<mvc:mapping path="/**"\
allowed-origins="*"\
allowed-methods="POST, GET, OPTIONS, DELETE, PUT"\
allowed-headers="Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"\
allow-credentials="true" />\
</mvc:cors>
注意解决跨域问题.
什么是跨域?
浏览器从一个域名的网页去请求另一个域名的资源时,域名、端口、协议任一不同,都是跨域.
域名:
主域名不同 www.baidu.com/index.html -->www.sina.com/test.js
子域名不同 www.666.baidu.com/index.html -->www.555.baidu.com/test.js
域名和域名ip www.baidu.com/index.html -->http://180.149.132.47/test.js
端口:
www.baidu.com:8080/index.html–… www.baidu.com:8081/test.js
协议:
www.baidu.com:8080/index.html–… www.baidu.com:8080/test.js
备注:
1、端口和协议的不同,只能通过后台来解决
2、localhost和127.0.0.1虽然都指向本机,但也属于跨域
另外一种解决方案是在控制器上添加@CrossOrigin注解.
或者自定义过滤器,进行跨域处理.
SqlMapConfig.xml