J2ee和java:我的函数java有问题,他没有';不能使用数据库(mysql)

J2ee和java:我的函数java有问题,他没有';不能使用数据库(mysql),java,mysql,jakarta-ee,Java,Mysql,Jakarta Ee,嘿,我的朋友,我的密码有点问题,他没用 我认为这个问题在我的类用户服务,但我不确定,请帮助我 当我运行我的程序时 我的主控台附言: On train de detecter UtlisateurAction.java package com.web.actions; import java.util.List; import com.app.business.bo.security.Role; import com.app.business.bo.security.Utlisateur;

嘿,我的朋友,我的密码有点问题,他没用 我认为这个问题在我的类用户服务,但我不确定,请帮助我 当我运行我的程序时 我的主控台附言:

On train de detecter
UtlisateurAction.java

package com.web.actions;

import java.util.List;

import com.app.business.bo.security.Role;
import com.app.business.bo.security.Utlisateur;
import com.app.business.services.UtlisateurService;
import com.app.exceptions.DuplicateLoginException;
import com.web.BaseAction;

public class UtlisateurAction extends BaseAction {



    private UtlisateurService userService;

    private List<Utlisateur> listUsers;

    private Utlisateur utilisateur;

    private List<Role> listRoles;

    private Long selectedRole;


    public String passage(){
        System.out.println("Passage");
    return SUCCESS;
    }
    public String showMenu(){
        System.out.println("User Access");
        return SUCCESS;
    }

    public String initFormAddUser() {
        listRoles = userService.getAllRoles();

        return SUCCESS;
    }

    public String addUser() {

        try {
            utilisateur.setRole(userService.getRoleById(selectedRole));
            userService.addUtilisateur(utilisateur);

        } catch (DuplicateLoginException ex) {
            addActionError("Operation non effectuee a  cause d'une erreur");

            ex.printStackTrace();
            return "error";

        } catch (Exception ex) {
            addActionError("Operation non effectuee à cause d'une erreur");

            ex.printStackTrace();
            return "error";

        }
        // on affiche une page d'erreur
        addActionMessage("Utilisateur ajoutée avec succées");
        return SUCCESS;
    }

    public String listUsers() {
        System.out.println("On train de detecter");
        listUsers = userService.getAllUsers();
        System.out.println("GET ALL USERS");
        return SUCCESS;
    }

    public List<Utlisateur> getListUsers() {
        return listUsers;
    }

    public void setListUsers(List<Utlisateur> listUsers) {
        this.listUsers = listUsers;
    }

    public UtlisateurService getUserService() {
        return userService;
    }

    public void setUserService(UtlisateurService userService) {
        this.userService = userService;
    }

    public Utlisateur getUtilisateur() {
        return utilisateur;
    }

    public void setUtilisateur(Utlisateur utilisateur) {
        this.utilisateur = utilisateur;
    }

    public List<Role> getListRoles() {
        return listRoles;
    }

    public void setListRoles(List<Role> listRoles) {
        this.listRoles = listRoles;
    }

    public Long getSelectedRole() {
        return selectedRole;
    }

    public void setSelectedRole(Long selectedRole) {
        this.selectedRole = selectedRole;
    }

}
utlisateurseservicepimpl.java

package com.services.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.bo.security.Role;
import com.bo.security.Utilisateur;
import com.boudaa.dao.exceptions.EntityNotFoundException;
import com.dao.RoleDao;
import com.dao.UtilisateurDao;
import com.exceptions.DuplicateLoginException;
import com.services.UtilisateurService;

public class UtilisateurServiceImpl implements UtilisateurService, UserDetailsService {

    private UtilisateurDao userDao;
    private RoleDao roleDao;

    protected final Log log = LogFactory.getLog(getClass());

    public UserDetails loadUserByUsername(String pLogin) throws UsernameNotFoundException {
        Utilisateur lUser = null;
        Collection<GrantedAuthority> arrayAuths = new ArrayList<GrantedAuthority>();

        // On récupère un objet de domaine de type User ayant comme login pLogin
        try {
            lUser = userDao.getUserByLogin(pLogin);

        } catch (ObjectRetrievalFailureException ex) {
            ex.printStackTrace();

            // nous relançons une UsernameNotFoundException si aucun utilisateur
            // ne correspond à cet login
            log.debug("Erreur d'authentification avec le login : " + pLogin);
            throw new UsernameNotFoundException("User " + pLogin + " not exists", ex);

        }


        // Si un utilisateur correspond à cet identifiant, nous en profitons
        // pour mettre à jour sa date de dernière connexion
        lUser.setLastAccessDate(Calendar.getInstance().getTime());
        userDao.update(lUser);
        // Il faut ensuite récupérer les rôles de l’utilisateur et les
        // mettre
        // sous la forme de SimpleGrantedAuthority, une interface propre à
        // Spring
        // Security*

        Role role = lUser.getRole();
        arrayAuths.add(new SimpleGrantedAuthority(role.getRoleName()));
        // /un User (classe Spring Security) est créé
        System.out.println("oui");
        return new User(pLogin, lUser.getPassword(), lUser.isEnabled(), lUser.isAccountNotExpired(), true,
                lUser.isAccountNotLocked(), arrayAuths);
    }


    public Utilisateur getUserByLogin(String pLogin) throws EntityNotFoundException {

        List<Utilisateur> users;
        try {
            users = userDao.getEntityByColumn("Utilisateur", "login", pLogin);

        } catch (ObjectRetrievalFailureException ex) {

            throw new EntityNotFoundException("Aucun utilisateur avec le login : " + pLogin);
        }

        if (users.size() != 1) {
            // TODO : Ecrire le code pour ajouter des log fatal
            // TODO : ecrire le code envoyant un mail d'erreur fatal à
            // l'administrateur

            throw new RuntimeException("Erreur inconnue dans le systeme");
        }

        return users.get(0);
    }
    public void addUtilisateur(Utilisateur user) throws DuplicateLoginException {

        // pour hacher avec SHA1
        ShaPasswordEncoder encoder = new ShaPasswordEncoder();


        // Hachage du mot de passe avec un gain de sel variable = login
        String cryptedPassword = encoder.encodePassword(user.getPassword(),
                user.getLogin());

        // affecter le mot de passe haché
        user.setPassword(cryptedPassword);

        // stockage de l'utilisateur dans la base de données
        try {
            userDao.create(user);

        } catch (DataIntegrityViolationException ex) {
            log.error("erreur d'ajout d'un utilisateur à cause de l'exception " + ex
                    + " . un utilisateur avec le login " + user.getLogin() + " existe déjà dans la base de données");
            throw new DuplicateLoginException("Erreur d'inscription, login existe déjà", ex);
        }

    }

    public Role getRoleByName(String roleName) {
        return roleDao.getRoleByName(roleName);
    }

    public Role getRoleById(Long pRoleId) throws EntityNotFoundException {
        return roleDao.findById(pRoleId);
    }

    public List<Utilisateur> getAllUsers() {
        return userDao.getAll();
    }

    public List<Role> getAllRoles() {
        return roleDao.getAll();
    }

    public void deleteUser(Utilisateur u) throws EntityNotFoundException {

        userDao.delete(u.getIdUtilisateur());

    }

    public UtilisateurDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UtilisateurDao userDao) {
        this.userDao = userDao;
    }

    public RoleDao getRoleDao() {
        return roleDao;
    }

    public void setRoleDao(RoleDao roleDao) {
        this.roleDao = roleDao;
    }


}
package com.services.impl;
导入java.util.ArrayList;
导入java.util.Calendar;
导入java.util.Collection;
导入java.util.List;
导入org.apache.commons.logging.Log;
导入org.apache.commons.logging.LogFactory;
导入org.springframework.dao.DataIntegrityViolationException;
导入org.springframework.orm.ObjectRetrievalFailureException;
导入org.springframework.security.authentication.encoding.ShaPasswordEncoder;
导入org.springframework.security.core.GrantedAuthority;
导入org.springframework.security.core.authority.SimpleGrantedAuthority;
导入org.springframework.security.core.userdetails.User;
导入org.springframework.security.core.userdetails.userdetails;
导入org.springframework.security.core.userdetails.userdetails服务;
导入org.springframework.security.core.userdetails.UsernameNotFoundException;
导入com.bo.security.Role;
进口com.bo.security.usilisateur;
导入com.boudaa.dao.exceptions.EntityNotFoundException;
进口com.dao.RoleDao;
进口com.dao.usilizateurdao;
导入com.exceptions.DuplicateLoginException;
导入com.services.usilizateurservice;
公共类UtiuseAtureService impl实现UtiuseAtureService、UserDetailsService{
私人使用乌尔道用户道;
列兵列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛列岛;
受保护的最终日志日志=LogFactory.getLog(getClass());
public UserDetails loadUserByUsername(字符串pLogin)引发UsernameNotFoundException{
利用率=零;
集合arrayAuths=新的ArrayList();
//在récupÃre un objet de domaine de type User ayant comme login pLogin上
试一试{
lUser=userDao.getUserByLogin(pLogin);
}捕获(ObjectRetrievalFailureException ex){
例如printStackTrace();
//我们的用户名称没有发现例外情况
//ne对应Ãcet登录
log.debug(“Erreur d'authentication avec le login:”+pLogin);
抛出新的UsernameNotFoundException(“用户”+pLogin+“不存在”,ex);
}
//没有使用相应的标识,没有利润
//重新连接的日期
lUser.setLastAccessDate(Calendar.getInstance().getTime());
userDao.update(lUser);
//Il faut套间récupÃrer les rô´les de l–Euro™利用率
//梅特
//简单的授权形式,不包括接口本身
//弹簧
//保安*
Role=lUser.getRole();
add(新的SimpleGrantedAuthority(role.getRoleName());
///un用户(弹簧安全等级)est crÃÃÃÃ)
系统输出打印项次(“oui”);
返回新用户(pLogin,lUser.getPassword(),lUser.isEnabled(),lUser.isAccountNoteExpired(),true,
lUser.isAccountNotLocked(),arrayAuths);
}
公共利用率我们的getUserByLogin(字符串pLogin)抛出EntityNotFoundException{
列出用户名单;
试一试{
users=userDao.getEntityByColumn(“利用者”、“登录者”、pLogin);
}捕获(ObjectRetrievalFailureException ex){
抛出新的EntityNotFoundException(“Aucun-usilizateur-avec-le-login:”+pLogin);
}
如果(users.size()!=1){
//TODO:Ecrire le code pour AJAOUTER des log致命
//待办事项:埃克莱尔·勒·代码特使联合国邮件
//行政官
抛出新的运行时异常(“Erreur inconue dans le systeme”);
}
返回用户。获取(0);
}
public void addutisulateur(utisulateur用户)引发重复登录异常{
//倒酒
ShaPasswordEncoder编码器=新的ShaPasswordEncoder();
//不可通过的信息的获取变量=登录
String cryptedPassword=encoder.encodePassword(user.getPassword(),
user.getLogin());
//受影响的人
user.setPassword(cryptedPassword);
//多恩斯基地利用率仓库
试一试{
创建(用户);
}捕获(DataIntegrityViolationException ex){
日志错误(“使用错误”导致异常“+ex
+“.un-usilizateur avec le login”+user.getLogin()+“existe déjÃdans la base de donnÃes”);
抛出新的DuplicateLoginException(“Erreur d'dentitle,login existe déjÔ,ex);
}
}
公共角色getRoleByName(字符串roleName){
返回roleDao.getRoleByName(roleName);
}
公共角色getRoleById(长pRoleId)引发EntityNotFoundException{
返回roleDao.findById(pRoleId);
}
公共列表getAllUsers(){
返回userDao.getAll();
}
公共列表getAllRoles(){
返回roleDao.getAll();
}
public void deleteUser(利用者u)引发EntityNotFoundException{
userDao.delete(u.getIDUsalisateur());
}
公共使用Urdao getUserDao(){
返回userDao;
}
public void setUserDao(usilisaturdao userDao){
this.userDao=userDao;
}
公共RoleDao getRoleDao(){
返回roleDao;
}
公共无效设置RoleDao(RoleDao RoleDao){
this.roleDao=roleDao;
}
}
applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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">
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost/services</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>azertyui</value>
        </property>
    </bean>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource">

        </property>
        <property name="mappingResources">
            <list>

            <value>com/app/business/dao/hbm/Utlisateur.hbm.xml</value>
            <value>com/app/business/dao/hbm/Filiere.hbm.xml</value>
            <value>com/app/business/dao/hbm/Matiere.hbm.xml</value>
            <value>com/app/business/dao/hbm/Niveau.hbm.xml</value>
            <value>com/app/business/dao/hbm/Document.hbm.xml</value>
            <value>com/app/business/dao/hbm/Role.hbm.xml</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQL5Dialect
                </prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>

                <prop key="hibernate.transaction.factory_class">
                    org.hibernate.transaction.JDBCTransactionFactory
                </prop>
            </props>

        </property>


    </bean>


    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

    <tx:advice id="defaultTxAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="loadUserByUsername" propagation="REQUIRED" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="defaultServiceOperation"
            expression="execution(* com.app.business.services.Impl.*Service*.*(..))" />
        <aop:advisor pointcut-ref="defaultServiceOperation"
            advice-ref="defaultTxAdvice" />
    </aop:config>

    <bean id="NiveauDao"
        class="com.app.business.dao.Impl.NiveauDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="DocumentDao"
        class="com.app.business.dao.Impl.DocumentDaoImp">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="FiliereDao"
        class="com.app.business.dao.Impl.FiliereDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="MatiereDao"
        class="com.app.business.dao.Impl.MatiereDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="DocumentService"
        class="com.app.business.services.Impl.DocumentServiceImpl">
        <property name="documentdao" ref="DocumentDao"></property>
    </bean>
    <bean id="UtlisateurDao"
        class="com.app.business.dao.Impl.UtlisateurDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="RoleDao" class="com.app.business.dao.Impl.RoleDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="UtlisateurService"
        class="com.app.business.services.Impl.UtlisateurServiceImpl">
        <property name="userDao" ref="UtlisateurDao"></property>
        <property name="roleDao" ref="RoleDao"></property>
    </bean>
    <bean id="UtlisateurAction"
        class="com.web.actions.UtlisateurAction" scope="prototype">
        <property name="userService" ref="UtlisateurService"></property>
    </bean>
    <bean id="SecurityAction" class="com.web.actions.SecurityAction" scope="prototype">
        <property name="utilisateurService" ref="UtlisateurService"></property>
    </bean>
</beans>

com.mysql.jdbc.Driver
jdbc:mysql://localhost/services
根
艾泽特尤伊
com/app/business/dao/hbm/Utlisateur.hbm
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    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">
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost/services</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>azertyui</value>
        </property>
    </bean>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource">

        </property>
        <property name="mappingResources">
            <list>

            <value>com/app/business/dao/hbm/Utlisateur.hbm.xml</value>
            <value>com/app/business/dao/hbm/Filiere.hbm.xml</value>
            <value>com/app/business/dao/hbm/Matiere.hbm.xml</value>
            <value>com/app/business/dao/hbm/Niveau.hbm.xml</value>
            <value>com/app/business/dao/hbm/Document.hbm.xml</value>
            <value>com/app/business/dao/hbm/Role.hbm.xml</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQL5Dialect
                </prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>

                <prop key="hibernate.transaction.factory_class">
                    org.hibernate.transaction.JDBCTransactionFactory
                </prop>
            </props>

        </property>


    </bean>


    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

    <tx:advice id="defaultTxAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="loadUserByUsername" propagation="REQUIRED" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="defaultServiceOperation"
            expression="execution(* com.app.business.services.Impl.*Service*.*(..))" />
        <aop:advisor pointcut-ref="defaultServiceOperation"
            advice-ref="defaultTxAdvice" />
    </aop:config>

    <bean id="NiveauDao"
        class="com.app.business.dao.Impl.NiveauDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="DocumentDao"
        class="com.app.business.dao.Impl.DocumentDaoImp">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="FiliereDao"
        class="com.app.business.dao.Impl.FiliereDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="MatiereDao"
        class="com.app.business.dao.Impl.MatiereDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="DocumentService"
        class="com.app.business.services.Impl.DocumentServiceImpl">
        <property name="documentdao" ref="DocumentDao"></property>
    </bean>
    <bean id="UtlisateurDao"
        class="com.app.business.dao.Impl.UtlisateurDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="RoleDao" class="com.app.business.dao.Impl.RoleDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="UtlisateurService"
        class="com.app.business.services.Impl.UtlisateurServiceImpl">
        <property name="userDao" ref="UtlisateurDao"></property>
        <property name="roleDao" ref="RoleDao"></property>
    </bean>
    <bean id="UtlisateurAction"
        class="com.web.actions.UtlisateurAction" scope="prototype">
        <property name="userService" ref="UtlisateurService"></property>
    </bean>
    <bean id="SecurityAction" class="com.web.actions.SecurityAction" scope="prototype">
        <property name="utilisateurService" ref="UtlisateurService"></property>
    </bean>
</beans>