Configurando Spring[RESOLVIDO]

10 respostas
E

Estou configurando o Spring, e no arquivo servlet-context.xml, esta dando erro :

Referenced file contains errors (http://www.springframework.org/schema/). For more information, right click on the message in
the Problems View and select “Show Details…”

Segue abaixo o meu servlet-context.xml:

<beans 
  	xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  	xmlns:beans="http://www.springframework.org/schema/beans"
  	xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:tx="http://www.springframework.org/schema/tx"
     	xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
    	  http://www.springframework.org/schema/
           beans/spring-beans-3.2.xsd
    	  http://www.springframework.org/schema/tx 
    	  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
          http://www.springframework.org/schema/mvc
    	  http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    	  http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/
           spring-context-3.2.xsd">

  <mvc:annotation-driven /> 

  <context:component-scan base-package="br.com.javamagazine"/>
   
  <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://ip:porta/database"/>
    <property name="username" value="username"/>
    <property name="password" value="password"/>    
  </bean>
   
  <bean id="mySessionFactory" class=
   "org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource"/>
    <property name="packagesToScan">
      <array>
        <value>br.com.javamagazine</value>
      </array>
    </property>
    <property name="hibernateProperties">
      <value>hibernate.dialect=org.hibernate.dialect.MySQLDialect
      </value>
    </property>
  </bean>
   
  <bean id="transactionManager" class=
   "org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="mySessionFactory"/>
  </bean>
   
  <tx:annotation-driven 
   transaction-manager="transactionManager"/>
</beans>

Alguem pode me ajudar ?

10 Respostas

alexfe

coloca esse bloco &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

Depois do

&lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

E

Alex, não entendi.

abc

alexfe

Desculpa tinha escrito errado

coloca esse bloco &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;

em baixo deste

&lt;mvc:annotation-driven /&gt;

ou substitui faz o teste ai

E

Alex,

tentei deixar da seguinte forma, mas o problema continua.

<mvc:annotation-driven /> 
  
  <tx:annotation-driven 
   transaction-manager="transactionManager"/>
alexfe

Veja se te ajuda

User este nome para seu arquivo applicationContext.xml

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
       http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
       http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" &gt;


	&lt;context:annotation-config /&gt;
    &lt;mvc:annotation-driven /&gt;
    &lt;mvc:default-servlet-handler /&gt;
	
	&lt;!-- ####### DATASOURCES ########## --&gt;
	&lt;bean id="dataSource"
		class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
		destroy-method="destroy" scope="singleton"&gt;
		
		&lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
		&lt;property name="url" value="jdbc:postgresql://localhost:5432/jalis_testeunitario" /&gt;
		&lt;property name="autoCommit" value="false" /&gt;
		&lt;property name="suppressClose" value="true" /&gt;
		&lt;property name="username" value="thread" /&gt;
		&lt;property name="password" value="murphy123" /&gt;
		
	&lt;/bean&gt;

	&lt;!-- SESSION FACTORY --&gt;
	&lt;bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
		scope="singleton"&gt;
		&lt;property name="dataSource"&gt;
			&lt;ref bean="dataSource" /&gt;
		&lt;/property&gt;
		&lt;property name="hibernateProperties"&gt;
			&lt;props&gt;
				&lt;prop key="hibernate.dialect"&gt;
					org.hibernate.dialect.PostgreSQLDialect
				&lt;/prop&gt;
				&lt;prop key="hibernate.default_schema"&gt;public&lt;/prop&gt;
				&lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
				&lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
				&lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt; &lt;!-- Gerenciamento de contexto automático da sessão do Hibernate --&gt;
				&lt;prop key="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/prop&gt;
				&lt;prop key="hibernate.c3p0.min_size"&gt;3&lt;/prop&gt; &lt;!-- Minimo de conexões do pool --&gt;
				&lt;prop key="hibernate.c3p0.max_size"&gt;8&lt;/prop&gt; &lt;!-- Máximo de conexões do pool --&gt;
				&lt;prop key="hibernate.c3p0.timeout"&gt;50&lt;/prop&gt; &lt;!-- Tempo em segundos --&gt;
				&lt;prop key="hibernate.connection.autocommit"&gt;false&lt;/prop&gt; &lt;!-- Auto commit --&gt;
				&lt;prop key="hibernate.c3p0.idle_test_period"&gt;50&lt;/prop&gt;
				&lt;prop key="hibernate.connection.pool_size"&gt;50&lt;/prop&gt; &lt;!-- Limita o numero de conexos aguarndando no pool --&gt;
				&lt;prop key="hibernate.c3p0.max_statements"&gt;1000&lt;/prop&gt; &lt;!-- Determina o limite maximo de de cache de comando sql do C3po --&gt;
				&lt;prop key="hibernate.c3p0.acquire_increment"&gt;5&lt;/prop&gt;
			&lt;/props&gt;
		&lt;/property&gt;
		&lt;property name="annotatedClasses"&gt;
			&lt;list&gt;
				&lt;value&gt;br.com.project.model.geral.Usuario&lt;/value&gt;&lt;!-- Classe de entidade persistentes --&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
		scope="singleton" autowire="autodetect"&gt;
		&lt;property name="dataSource"&gt;
			&lt;ref bean="dataSource" /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager"
		scope="singleton" lazy-init="default" autowire="byName"&gt;
		&lt;property name="sessionFactory"&gt;
			&lt;ref bean="sessionFactory" /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	
	&lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt;
	&lt;!-- =======================================FIM DA CONFIGURAÇÃO DE CONEXÃO================================================================================================ --&gt;

	&lt;!-- Controllers --&gt;

	&lt;!-- Repositorios interfaces --&gt;

	&lt;!-- Servicos interfaces --&gt;

&lt;/beans&gt;
E

Alex,

copiei o seu código e agora mudou o erro :

Description Resource Path Location Type
The processing instruction target matching “[xX][mM][lL]” is not allowed. servlet-context.xml /SpringDevmedia/src/main/webapp/WEB-INF/spring/appServlet line 1 XML Problem

alexfe

Vc temque ajustar ao projeto, verificar se falta Jars. Mas deixe o cabecalho do XML assim e tente novamente

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 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" default-lazy-init="true"&gt;

E

deixei dessa forma :

<?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"
	xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        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">

	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

	<!-- Scans within the base package of the application for @Components to configure as beans -->
	<!-- @Controller, @Service, @Configuration, etc. -->
	<context:component-scan base-package="xyz.sample.baremvc" />

	<!-- Enables the Spring MVC @Controller programming model -->
	<mvc:annotation-driven />

</beans>
alexfe

deu certo ?

E

deixei na configuração acima e não deu mais o erro.

Criado 27 de janeiro de 2015
Ultima resposta 29 de jan. de 2015
Respostas 10
Participantes 2