SSM项目链接 mysql正常,sqlserver连接失败,求高手帮助

wz334809916 2017-08-21 10:33:30
这是我的配置文件
<?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:cxt="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">

<!-- mysql -->
<!-- <bean id="dataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/jcdata??useUnicode=true&characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="zaih1009"/>
</bean> -->
<!-- sqlserver -->
<bean id="dataSource" class="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=jcdata" />
<property name="user" value="sa" />
<property name="password" value="zaih1009"/>
</bean>

<!-- 实现类 -->
<cxt:annotation-config />
<cxt:component-scan base-package="com.wz.service.impl" />
<!--mybatis数据配置 -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 扫描实体类 -->
<property name="typeAliasesPackage" value="com.wz.mybatis.entity" />
</bean>
<!-- 扫描mapper文件包 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.wz.mybatis.mapper" />
</bean>
<!-- hibernate <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" /> <property name="hibernateProperties">
<value> hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.show_sql=true
hibernate.format_sql=true hibernate.hbm2ddl.auto=update </value> </property>
<property name="packagesToScan" value="com.yvdedu.Experiment.entiy" /> </bean>
<bean class="org.springframework.orm.hibernate4.HibernateTemplate"> <property
name="sessionFactory" ref="sessionFactory" /> </bean> -->

<!-- 权限配置 -->
<bean id="userRealms" class="com.wz.shiro.UserRealm" />

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="userRealms" />
</bean>



<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="loginUrl" value="/login" />
<property name="successUrl" value="/index" />
<property name="unauthorizedUrl" value="/perms" />
<property name="filters">
<map>
<entry key="perms">
<bean class="com.wz.shiro.PermFitler"></bean>
</entry>
</map>
</property>
<property name="filterChainDefinitions">
<value>
/login = anon
/dologin = anon
/QueryStationByLines = anon
/QueryCodexByStation = anon
/QueryUserByStation = anon
/static/** = anon
/** = authc
/** = perms
</value>
</property>
</bean>



<!-- <aop:config> <aop:advisor advice-ref="myad" pointcut="execution(* com.wz.service.impl.*.*(..))"
/> </aop:config> -->
<!-- 文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10485760" />
</bean>
</beans>





这个配置文件中 mysql可以完美运行,切换到 sqlserver就跑不通。额求高手帮忙解决
...全文
394 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wz334809916 2017-08-25
  • 打赏
  • 举报
回复
引用 4 楼 u010049086 的回复:
spring自带数据源的配置方式

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
       
        <property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=db" />  
        <property name="username" value="sa" />  
        <property name="password" value="sa" /> 
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
 </bean>
额 从2008R2换成 2008没毛病了 不知道怎么回事
WonHyo 2017-08-22
  • 打赏
  • 举报
回复
spring自带数据源的配置方式

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
       
        <property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=db" />  
        <property name="username" value="sa" />  
        <property name="password" value="sa" /> 
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
 </bean>
wz334809916 2017-08-21
  • 打赏
  • 举报
回复
引用 2 楼 pany1209 的回复:
Invalid property 'url' of bean class [com.microsoft.sqlserver.jdbc.SQLServerDriver]: Bean property 'url' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?。。。 SQLServerDriver没有url属性。。。应该使用数据库连接池类把驱动配置到driverClassName之类的属性上 例如使用DruidDataSource,把com.microsoft.sqlserver.jdbc.SQLServerDriver配置到driverClassName属性
用 driverClassName 设置之后 给我报错 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。 我很确定 我都开着呢啊。。
李德胜1995 2017-08-21
  • 打赏
  • 举报
回复
Invalid property 'url' of bean class [com.microsoft.sqlserver.jdbc.SQLServerDriver]: Bean property 'url' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?。。。 SQLServerDriver没有url属性。。。应该使用数据库连接池类把驱动配置到driverClassName之类的属性上 例如使用DruidDataSource,把com.microsoft.sqlserver.jdbc.SQLServerDriver配置到driverClassName属性
wz334809916 2017-08-21
  • 打赏
  • 举报
回复
下面是报错信息:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'userRealms' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealms': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userinfoServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userinfoMapper' defined in file [G:\work\myweb\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Jcdata\WEB-INF\classes\com\wz\mybatis\mapper\UserinfoMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.SqlSessionFactoryBean#0' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'url' of bean class [com.microsoft.sqlserver.jdbc.SQLServerDriver]: Bean property 'url' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:235)
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:702)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:527)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'userRealms' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealms': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userinfoServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userinfoMapper' defined in file [G:\work\myweb\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Jcdata\WEB-INF\classes\com\wz\mybatis\mapper\UserinfoMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.SqlSessionFactoryBean#0' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'url' of bean class [com.microsoft.sqlserver.jdbc.SQLServerDriver]: Bean property 'url' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
	... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealms': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userinfoServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userinfoMapper' defined in file [G:\work\myweb\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Jcdata\WEB-INF\classes\com\wz\mybatis\mapper\UserinfoMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.SqlSessionFactoryBean#0' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataS
B

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧