I'm creating a GAE project with Spring which will also use cloud SQL. While testing this app in local I'm pointing to my local MySQL environment but when I'll deploy it to GAE, it will point to cloud SQL instance. So I want to configure my driverName in datasource bean depending on environment. To this we generally use following in our java code
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
// Load the class that provides the new "jdbc:google:mysql://" prefix.
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://<your-project-id>:<your-instance-name>/<your-database-name>?user=root";
} else {
// Local MySQL instance to use during development.
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://127.0.0.1:3306/<your-database-name>?user=root";
}
Now I want to achieve the same in applicationcontext.xml using Spring Expression language. I haven't done this before and not able to achieve it. Please guide me. This is what I tried
<bean id="isDev" class="java.lang.Boolean">
<constructor-arg value="#{ systemProperties[environment.value] == SystemProperty.Environment.Value.Development ? true : false }" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="#{ isDev ? com.mysql.jdbc.Driver : com.mysql.jdbc.GoogleDriver }" />
.
.
.
But I'm getting exception, attaching a part of exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedbackFormController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.sandeepapplabs.custengage.services.FeedbackFormService com.sandeepapplabs.custengage.controllers.FeedbackFormController.feedbackFormService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedbackFormService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.sandeepapplabs.custengage.daos.FeedbackFormDAO com.sandeepapplabs.custengage.services.impl.FeedbackFormServiceImpl.feedbackFormDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedbackFormDAO' defined in ServletContext resource [/WEB-INF/custengage-servlet.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 ServletContext resource [/WEB-INF/custengage-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is java.lang.NullPointerException
I believe you need to quote the class names to make them literals...
... 'com.mysql.jdbc.Driver' ...
However it is easier to use Spring Profiles](http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/beans.html#beans-definition-profiles-xml) and enable the profile you want.
You can use Spring profiles to change concrete bean classes. Let's say you have 2 profiles: "prod" and "dev". Your bean methods should have #Profile annotation as below:
#Configuration
public class AppConfig {
...
#Bean
#Profile("prod")
public Object prodDataSource() {
return new ...
}
#Bean
#Profile("dev")
public Object getDataSource() throws Exception {
return new ...
}
}
If you are using Maven, you can select profile through pom.xml:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profile>dev</spring.profile>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>prod</name>
</property>
</activation>
<properties>
<spring.profile>prod</spring.profile>
</properties>
</profile>
</profiles>
You can pass profile selection argument by -D like: mvn -Dprod clean compile test install
EDIT:
In application.properties following property selects profile:
spring.profiles.active=${spring.profile}
Related
I'm about start with a web application project and I am trying to integrate Mysql into Grails 3. All of the online tutorials show us to change the DataSource file which does not currently (there is Application.yml).
I tried changing the Application.yml as given in the official documentation, but it gives me a big error. Its a new project and has no other changes to it. I've used grails 2.4 previously, it was really easy with that and now I'm thinking of changing back.
Change:
dataSource :
pooled : true
dbCreate : "update"
url : "jdbc:mysql://localhost:3306/my_database"
driverClassName : "com.mysql.jdbc.Driver"
dialect : org.hibernate.dialect.MySQL5InnoDBDialect
username : "username"
password : "password"
properties :
jmxEnabled : true
initialSize : 5
maxActive : 50
minIdle : 5
maxIdle : 25
maxWait : 10000
maxAge : 10 * 60000
timeBetweenEvictionRunsMillis : 5000
minEvictableIdleTimeMillis : 60000
validationQuery : "SELECT 1"
validationQueryTimeout : 3
validationInterval : 15000
testOnBorrow : true
testWhileIdle : true
testOnReturn : false
jdbcInterceptors : "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation :
java.sql.Connection.TRANSACTION_READ_COMMITTED
the error I get:
/usr/lib/jvm/java-8-oracle/bin/java -XX:+TieredCompilation -
XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Dfile.encoding=UTF-8 -
classpath /home/nischit/.gradle/caches/modules-2/files-
2.1/org.grails/grails-
shell/3.2.10/c6b000bbb8ac369a9be062f08e8a0a8d3f85705/grails-shell-
3.2.10.jar:/home/nischit/.gradle/caches/modules-2/files-
2.1/org.slf4j/slf4j-
simple/1.7.25/8dacf9514f0c707cbbcdd6fd699e8940d42fb54e/slf4j-simple-
1.7.25.jar:/home/nischit/.gradle/caches/modules-2/files-
2.1/org.codehaus.plexus/plexus-component-api/1.0-alpha-
33/7d9560effcadf867937ac6885d0d1045ea98ab59/plexus-component-api-1.0-
alpha-33.jar:/home/nischit/.gradle/caches/modules-2/files
Running application...
2017-10-02 01:42:14.120 ERROR --- [ost-startStop-1]
o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat
context. Exception:
org.springframework.beans.factory.BeanCreationException. Message:
Error creating bean with name 'grailsCacheFilter': Cannot create
inner bean '(inner bean)#17d4fdc1' of type
[grails.plugin.cache.web.filter.
simple.MemoryPageFragmentCachingFilter]
while setting bean property 'filter'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
at grails.boot.GrailsApp$run.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.
defaultCall(CallSiteArray.java:48)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsCacheFilter': Cannot create
inner bean '(inner bean)#17d4fdc1' of type
[grails.plugin.cache.web.filter.simple.
MemoryPageFragmentCachingFilter] while setting bean property
'filter'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error c
reating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
at
org.springframework.beans.factory.support.
BeanDefinitionValueResolver.resolveInnerBean
(BeanDefinitionValueResolver.java:313)
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
at
org.springframework.beans.factory.annotation.
AutowiredAnnotationBeanPostProcessor
$AutowiredMethodElement.inject
(AutowiredAnnotationBeanPostProcessor.java:667)
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with
non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info
or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full
trace)
The problem is with the way you're trying to set the maxAge value on your data source:
Failed to convert property value of type 'java.lang.String' to
required type 'long' for property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
Try just setting a concrete value rather than a calculation.
If you are not very comfortable with YML standard then simply create a new file with name application.groovy, place it inside the conf directory and add the datasource block in that groovy file. Don't forget to remove the data source block from application.yml file.
Im am creating spring security with role based authentication project demo but getting issue like
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
my Helloworldcontroller.java is
package com.srk.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.srk.service.UserService;
import com.srk.service.UserServiceImpl;
#Controller
public class HelloWorldController {
// protected final Log logger = LogFactory.getLog(getClass());
#Autowired
UserService userService;
#RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
public String homePage(ModelMap model) {
model.addAttribute("greeting", "Hi, Welcome to mysite");
return "welcome";
}
#RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminPage(ModelMap model) {
model.addAttribute("user", getPrincipal());
return "admin";
}
#RequestMapping(value = "/db", method = RequestMethod.GET)
public String dbaPage(ModelMap model) {
model.addAttribute("user", getPrincipal());
return "dba";
}
#RequestMapping(value = "/Access_Denied", method = RequestMethod.GET)
public String accessDeniedPage(ModelMap model) {
model.addAttribute("user", getPrincipal());
return "accessDenied";
}
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage() {
return "login";
}
#RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logoutPage(HttpServletRequest request, HttpServletResponse response) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null) {
new SecurityContextLogoutHandler().logout(request, response, auth);
}
return "redirect:/login?logout";
}
private String getPrincipal() {
String userName = null;
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
userName = ((UserDetails) principal).getUsername();
} else {
userName = principal.toString();
}
return userName;
}
}
AbstractDao.java is
package com.srk.dao;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class AbstractDao<PK extends Serializable, T> {
private final Class<T> persistentClass;
#SuppressWarnings("unchecked")
public AbstractDao(){
this.persistentClass =(Class<T>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
}
#Autowired
private SessionFactory sessionFactory;
protected Session getSession(){
return sessionFactory.getCurrentSession();
}
#SuppressWarnings("unchecked")
public T getByKey(PK key) {
return (T) getSession().get(persistentClass, key);
}
public void persist(T entity) {
getSession().persist(entity);
}
public void delete(T entity) {
getSession().delete(entity);
}
protected Criteria createEntityCriteria(){
return getSession().createCriteria(persistentClass);
}
}
UserDaoImpl.java is
package com.srk.dao;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.srk.model.User;
#Repository
public class UserDaoImpl extends AbstractDao<Integer, User> implements UserDao {
#Autowired
SessionFactory sessionFactory;
public User findById(int id) {
return getByKey(id);
}
public User findBySSO(String sso) {
Criteria crit = createEntityCriteria();
crit.add(Restrictions.eq("ssoId", sso));
return (User) crit.uniqueResult();
}
}
UserServiceImple.java is
package com.srk.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.srk.dao.UserDao;
import com.srk.dao.UserDaoImpl;
import com.srk.model.User;
#Service
#Transactional
public class UserServiceImpl implements UserService{
#Autowired
UserDao userDao;
public User findById(int id) {
return userDao.findById(id);
}
public User findBySso(String sso) {
return userDao.findBySSO(sso);
}
}
sdnext-servlet.xml is
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<context:component-scan base-package="com.srk.*" />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="jspViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
id="dataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/springsecurity" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
id="sessionFactory">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.srk.model.User</value>
</list>
</property>
<!-- <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}
</prop> </props> </property> -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">true</prop>
</props>
</property>
</bean>
<bean class="org.springframework.orm.hibernate4.HibernateTransactionManager"
id="hibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<mvc:resources mapping="/static/**" location="/static/" />
<security:http auto-config="true">
<security:intercept-url pattern="/" access="permitAll" />
<security:intercept-url pattern="/home" access="permitAll" />
<security:intercept-url pattern="/admin**"
access="hasRole('ADMIN')" />
<security:intercept-url pattern="/dba**"
access="hasRole('ADMIN') and hasRole('DBA')" />
<security:form-login login-page="/login"
username-parameter="ssoId" password-parameter="password"
authentication-success-handler-ref="customSuccessHandler"
authentication-failure-url="/Access_Denied" />
<security:csrf />
</security:http>
<security:authentication-manager>
<security:authentication-provider
user-service-ref="customUserDetailsService" />
</security:authentication-manager>
<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="customUserDetailsService" class="com.srk.service.CustomUserDetailsService" />
<bean id="customSuccessHandler" class="com.srk.configuration.CustomSuccessHandler" />
<bean id="userDao" class="com.srk.dao.UserDaoImpl" />
<bean id="userService" class="com.srk.service.UserServiceImpl" />
</beans>
And My jars are
antlr-2.7.7
aopalliance-1.0
commons-logging-1.2
dom4j-1.6.1
hibernate-commons-annotations-4.0.5.Final
hibernate-core-4.3.6.Final
hibernate-jpa-2.1-api-1.0.0.Final
jandex-1.1.0.Final
javassist-3.18.1-GA
javax.servlet.jsp-api-2.3.1
javax.servlet-api-3.1.0
jstl-1.2
jta-1.1
mysql-connector-java-5.1.31
spring-aop-4.1.6.RELEASE
spring-beans-4.1.6.RELEASE
spring-context-4.1.6.RELEASE
spring-core-4.1.6.RELEASE
spring-expression-4.1.6.RELEASE
spring-jdbc-4.1.6.RELEASE
spring-orm-4.1.6.RELEASE
spring-security-config-4.0.1.RELEASE
spring-security-core-4.0.1.RELEASE
spring-security-web-4.0.1.RELEASE
spring-tx-4.1.6.RELEASE
spring-web-4.1.6.RELEASE
spring-webmvc-4.1.6.RELEASE
xml-apis-1.0.b2
Please help me....i stuck in code .....Thanks in advance
Error is:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.srk.dao.UserDaoImpl com.srk.service.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.srk.dao.UserDaoImpl com.srk.service.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 49 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 51 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 62 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 64 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 74 more
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.srk.service.UserServiceImpl com.srk.controller.HelloWorldController.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.srk.dao.UserDaoImpl com.srk.service.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 36 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.srk.dao.UserDaoImpl com.srk.service.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 38 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.srk.dao.UserDaoImpl com.srk.service.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 49 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 51 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.srk.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
at
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/sdnext-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.orm.hibernate4.LocalSessionFactoryBuilder
try, changing to
<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
id="sessionFactory">
<constructor ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.srk.model.User</value>
</list>
</property>
<!-- <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}
</prop> </props> </property> -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">true</prop>
</props>
</property>
</bean>
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.html
Since I have problems with the serviceRegisty.conf, I tried the serviceRegistryDao:
<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
<property name="registeredServices">
<list>
<bean class="org.jasig.cas.services.RegisteredServiceImpl">
<property name="id" value="0" />
<property name="name" value="HTTPS" />
<property name="description" value="Only Allows HTTPS Urls" />
<property name="serviceId" value="https://**" />
<property name="evaluationOrder" value="10000001" />
<property name="allowedAttributes">
<list>
<value>cn</value>
<value>description</value>
<value>telephoneNumber</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
If I don't use "allowedAttributes" everything works fine, but I don't get the attributes I want (I get non). So guessed that I need to add which attribute the clients should recieve. However, I get the following exception:
2016-09-21 16:17:40,674 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'centralAuthenticationService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultTicketRegistry': Inject
ion of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.jasig.cas.logout.LogoutManager org.jasig.cas.ticket.registry.DefaultTicketRegistry.logoutManager; nested exception is org.springframework.beans.fac
tory.BeanCreationException: Error creating bean with name 'logoutManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.jasig.cas.services.ServicesManager org.jasig.cas.logout.LogoutMana
gerImpl.servicesManager; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servicesManager' defined in URL [jar:file:/D:/Tomcat%20Servers/Tomcat%20CAS%20Server/webapps/cas/WEB-INF/lib/cas-server-core-services-4.2.0.jar!/org/jasig/cas
/services/DefaultServicesManagerImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.jasig.cas.services.ServiceRegistryDao]: : Error creating bean with name 'serviceRegistryDao' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: C
annot create inner bean 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' of type [org.jasig.cas.services.RegisteredServiceImpl] while setting bean property 'registeredServices' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'allowedAttributes' of bean class [org.jas
ig.cas.services.RegisteredServiceImpl]: Bean property 'allowedAttributes' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'serviceRegistryDao' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Cannot create inner bean 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' of type [org.jasig.cas.services.RegisteredServiceImpl] while setting bean property 'registeredServices' with key [0]; n
ested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.jasig.cas.services.RegisteredServiceImpl#286fad61' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Error setting property values; nested exception is org.springfram
ework.beans.NotWritablePropertyException: Invalid property 'allowedAttributes' of bean class [org.jasig.cas.services.RegisteredServiceImpl]: Bean property 'allowedAttributes' 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.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1795)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
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:745)
My suspicion is that this way of dealing with services is no longer supported by CAS 4.2.x, but I am not sure.
EDIT:
I also tried this:
<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
<property name="registeredServices">
<list>
<bean class="org.jasig.cas.services.RegexRegisteredService"
p:id="5" p:name="https.all" p:description="Allow HTTPS connection"
p:serviceId="^https://.*" p:evaluationOrder="5" >
<property name="attributeReleasePolicy">
<bean class="org.jasig.cas.services.ReturnAllAttributeReleasePolicy" />
</property>
</bean>
</list>
</property>
</bean>
I thought by that I might get all attributes. I can run the tomcat server now and also log in etc. But I still dont get the attributes.
The configuration is invalid because that's not how 4.2 works. Consult the docs to learn the new syntax. You also need to make sure your application is hitting the right endpoint.
I have a Gradle Spring Boot web application that migrates from H2 to PostgreSQL using Flyway. I am trying to convert this to migrate from H2 to MySQL. The build.gradle file is:
buildscript {
ext {
springBootVersion = '1.3.0.RELEASE'
}
repositories {
maven { url "http://repo.spring.io/milestone" }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
archiveName = 'demo.war'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven { url "http://repo.spring.io/milestone" }
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("com.h2database:h2")
compile("org.postgresql:postgresql:9.4-1201-jdbc41")
compile("org.flywaydb:flyway-core")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
There is an application.yml file:
error:
whitelabel:
enabled: false
amazon:
associate_id: habuma-20
spring:
jpa:
hibernate:
ddl-auto: none
---
spring:
profiles: production
datasource:
url: jdbc:postgresql://localhost:5432/readinglist
username: habuma
password:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
In build.gradle, I replaced
compile("org.postgresql:postgresql:9.4-1201-jdbc41")
with
compile("mysql:mysql-connector-java:5.1.5")
and changed application.yml to
error:
whitelabel:
enabled: false
amazon:
associate_id: habuma-20
spring:
jpa:
hibernate:
ddl-auto: none
---
spring:
profiles: production
datasource:
url: jdbc:mysql://localhost:3306/readinglist
username: root
password: ******
jpa:
database-platform: org.hibernate.dialect.MySQL5Dialect
To get the "production" profile I set an environment variable SPRING_PROFILES_ACTIVE=production. Then run with the command java -jar build/libs/demo.war. When the application tries to boot up I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception;
nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private readinglist.ReaderRepository readinglist.SecurityConfig.readerRepository;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readerRepository': Cannot create inner bean '(inner bean)#1c65a791' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1c65a791': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed;
nested exception is org.flywaydb.core.api.FlywayException: Validate failed. Migration Checksum mismatch for migration 1
I'm not sure what the solution to this Checksum mismatch is.
I'm attempting create a simple web app with a MySQL backend. I'm able to deploy my .ear in Geronimo. However, when I submit my form to persist some stuff to the DB via OpenJPA I get the following error (below is my stacktrace):
Caused by: org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
My Project is an Enterprise Application Project (AReyes) with a web module (AReyesAdminWeb) and an ejb module (AReyesEJB).
My persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="AReyesPersistUnit" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>AReyesMySql</jta-data-source>
<class>com.areyes.entity.Admin</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
</properties>
</persistence-unit>
</persistence>
The file is located in AReyesEJB/ejbModule/META-INF
What I'm using
Geronimo 2.2.1 with Tomcat 6
MySQL 5.5.11
OpenJPA 1.2.2
Eclipse Indego Release
OS X 10.6.7
StackTrace
Caused by: org.apache.openejb.OpenEJBException: Error while creating bean com.areyes.session.AdminManager: Error invoking constructor: public com.areyes.session.AdminManager()
at org.apache.openejb.InjectionProcessor.construct(InjectionProcessor.java:120)
at org.apache.openejb.InjectionProcessor.createInstance(InjectionProcessor.java:83)
at org.apache.openejb.core.stateless.StatelessInstanceManager.ceateInstance(StatelessInstanceManager.java:204)
at org.apache.openejb.core.stateless.StatelessInstanceManager.getInstance(StatelessInstanceManager.java:165)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
... 23 more
Caused by: org.apache.xbean.recipe.ConstructionException: Error invoking constructor: public com.areyes.session.AdminManager()
at org.apache.xbean.recipe.ReflectionUtil$ConstructorFactory.create(ReflectionUtil.java:962)
at org.apache.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:276)
at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96)
at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:61)
at org.apache.openejb.InjectionProcessor.construct(InjectionProcessor.java:118)
... 30 more
Caused by: <openjpa-1.2.2-r422266:898935 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:74)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:784)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:561)
at org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1344)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:505)
at org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:430)
at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103)
at org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:863)
at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:854)
at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
at com.areyes.session.AdminManager.<init>(AdminManager.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.xbean.recipe.ReflectionUtil$ConstructorFactory.create(ReflectionUtil.java:952)
... 34 more
com.areyes.session.AdminManager is a #Stateless bean that has been injected into a servlet in AReyesAdminWeb (with #EJB anno). Here's the constrcutor:
#Stateless
public class AdminManager implements AdminService {
private EntityManagerFactory fac;
private EntityManager em;
public AdminManager () {
fac = Persistence.createEntityManagerFactory("AReyesPersistUnit", System.getProperties());
em = fac.createEntityManager();
}
The behavior seem like my web app is unaware of my persistence.xml in my ejb app. I wonder if I bundled everything up correctly.
I added this to my application.xml:
<module>
<connector>tranql-connector-mysql-local-1.5.rar</connector>
</module>
Then I added this to my geronimo-application.xml:
<app:module>
<app:connector>tranql-connector-mysql-local-1.5.rar</app:connector>
<app:alt-dd>mysql-plan.xml</app:alt-dd>
</app:module>
In my EA Project (AReyes) I've added mysql-plan.xml in the same folder with my META-INF. Then I imported the tranql-connector-mysql-local-1.5.rar from my Geronimo folder.
It sounds like the web app cannot find persistence.xml on its class path. From reading this thread you could have the same problem. Try moving persistence.xml to the following location and see how you go...
WEB-INF/classes/META-INF/persistence.xml